a4b5cd4834
- Cambiati nomi classi e file.
773 lines
27 KiB
VB.net
773 lines
27 KiB
VB.net
Imports System.Collections.ObjectModel
|
|
Imports System.IO
|
|
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 SIM_ST = SIM_ST.ST_STOP
|
|
Private Property SimulationStatus As SIM_ST
|
|
Get
|
|
Return m_nStatus
|
|
End Get
|
|
Set(value As SIM_ST)
|
|
m_nStatus = value
|
|
If IniFile.m_nUserLevel >= 5 AndAlso (value = SIM_ST.ST_PAUSE OrElse value = SIM_ST.ST_STOP) Then
|
|
For Index = 0 To m_MachineAxisList.Count - 1
|
|
m_MachineAxisList(Index).IsReadOnlyAxesValue = False
|
|
Next
|
|
Else
|
|
For Index = 0 To m_MachineAxisList.Count - 1
|
|
m_MachineAxisList(Index).IsReadOnlyAxesValue = True
|
|
Next
|
|
End If
|
|
EgtSimSetUiStatus(m_nStatus)
|
|
End Set
|
|
End Property
|
|
|
|
' Stato bottone Play
|
|
Private m_bShowPlay As Boolean = True
|
|
' Coefficiente per valore Slider
|
|
Private m_SliderX As Double = 1
|
|
|
|
' Flag di esecuzione in corso
|
|
Private m_bSimExecuting As Boolean = False
|
|
|
|
'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
|
|
EgtDeselectAll()
|
|
Application.Msn.NotifyColleagues(Application.REMOVEMARKFROMLASTOPERATION)
|
|
Application.Msn.NotifyColleagues(Application.GETDISTANCE_ISCHECKED, False)
|
|
Map.refTopCommandBarVM.SaveIsEnabled = False
|
|
If IniFile.m_bShowOnlyTable Then
|
|
EgtShowOnlyTable(False)
|
|
EgtZoom(ZM.ALL, False)
|
|
End If
|
|
InitializeSimulation()
|
|
EgtDraw()
|
|
Else
|
|
If m_bSimExecuting Then Return
|
|
CloseSimulation()
|
|
If IniFile.m_bShowOnlyTable Then
|
|
EgtShowOnlyTable(True)
|
|
EgtZoom(ZM.ALL)
|
|
End If
|
|
Map.refTopCommandBarVM.SaveIsEnabled = True
|
|
End If
|
|
m_IsExpanded = value
|
|
Application.Msn.NotifyColleagues(Application.SIMULATIONEXPANDER_GET_ISEXPANDED, value)
|
|
OnPropertyChanged("IsExpanded")
|
|
OnPropertyChanged("GenerateIsEnabled")
|
|
End If
|
|
End Set
|
|
End Property
|
|
Public ReadOnly Property GenerateIsEnabled As Boolean
|
|
Get
|
|
Return Not m_IsExpanded
|
|
End Get
|
|
End Property
|
|
|
|
' 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
|
|
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_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
|
|
OnPropertyChanged("OpeName")
|
|
End If
|
|
End Set
|
|
End Property
|
|
|
|
Private m_PlayPauseImage As String
|
|
Public ReadOnly Property PlayPauseImage As String
|
|
Get
|
|
If m_bShowPlay Then
|
|
Return "/Resources/OptionPanel/MachiningOptionPanel/SimulationExpander/Play.png"
|
|
Else
|
|
Return "/Resources/OptionPanel/MachiningOptionPanel/SimulationExpander/Pause.png"
|
|
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
|
|
OnPropertyChanged("StatusMsg")
|
|
End Set
|
|
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
|
|
|
|
Private m_VMillActive As Boolean = False
|
|
Public Property VMillActive As Boolean
|
|
Get
|
|
Return m_VMillActive
|
|
End Get
|
|
Set(value As Boolean)
|
|
m_VMillActive = value
|
|
OnPropertyChanged("VMillActive")
|
|
If m_VMillActive Then
|
|
EgtSetInfo(EgtGetCurrMachGroup(), KEY_MCHGRP_VM, m_VMillActive)
|
|
Else
|
|
EgtRemoveInfo(EgtGetCurrMachGroup(), KEY_MCHGRP_VM)
|
|
End If
|
|
Application.Msn.NotifyColleagues(Application.EMITTITLE)
|
|
End Set
|
|
End Property
|
|
Public Sub SetVMillActive(value As Boolean)
|
|
m_VMillActive = value
|
|
OnPropertyChanged("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
|
|
OnPropertyChanged("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
|
|
OnPropertyChanged("VMill_IsEnabled")
|
|
End Set
|
|
End Property
|
|
|
|
' Definizione comandi
|
|
Private m_cmdStep As ICommand
|
|
Private m_cmdPlayPause As ICommand
|
|
Private m_cmdStop As ICommand
|
|
Private m_cmdGenerate As ICommand
|
|
|
|
#Region "Messages"
|
|
|
|
Public ReadOnly Property SimulationMsg As String
|
|
Get
|
|
Return EgtMsg(MSG_SIMULATION + 7) 'Simulazione
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property GenerateMsg As String
|
|
Get
|
|
Return EgtMsg(MSG_SIMULATION + 30) 'GENERA
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property VMillMsg As String
|
|
Get
|
|
Return EgtMsg(MSG_SIMULATION + 16) 'Virtual Milling
|
|
End Get
|
|
End Property
|
|
|
|
#End Region
|
|
|
|
#Region "ToolTip"
|
|
|
|
Public ReadOnly Property OneStepToolTip As String
|
|
Get
|
|
Return EgtMsg(MSG_SIMULATION + 8)
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property PlayPauseToolTip As String
|
|
Get
|
|
Return EgtMsg(MSG_SIMULATION + 9)
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property StopHomeToolTip As String
|
|
Get
|
|
Return EgtMsg(MSG_SIMULATION + 10)
|
|
End Get
|
|
End Property
|
|
|
|
#End Region
|
|
|
|
#End Region
|
|
|
|
#Region "CONSTRUCTOR"
|
|
|
|
Sub New()
|
|
Application.Msn.Register(Application.CLOSEAPPLICATION, Sub()
|
|
If IsExpanded Then
|
|
ResetSimulation()
|
|
End If
|
|
End Sub)
|
|
Application.Msn.Register(Application.SIMULATIONEXPANDER_SET_ISEXPANDED, Sub(bValue As Boolean)
|
|
IsExpanded = bValue
|
|
End Sub)
|
|
Application.Msn.Register(Application.SIMULATIONEXPANDER_UPDATE_CNCDATA, Sub()
|
|
If IsExpanded Then
|
|
ShowCncData()
|
|
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)
|
|
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)
|
|
StatusMsg = ""
|
|
' Disabilito check VMill
|
|
VMill_IsEnabled = False
|
|
' Se stato stop, devo avviare simulazione
|
|
If m_nStatus = SIM_ST.ST_STOP Then
|
|
SimulationStatus = SIM_ST.ST_STEP
|
|
' Aggiorno bottone
|
|
m_bShowPlay = False
|
|
OnPropertyChanged("PlayPauseImage")
|
|
ExecSim()
|
|
' Aggiorno bottone
|
|
m_bShowPlay = True
|
|
OnPropertyChanged("PlayPauseImage")
|
|
' Alrimenti imposto solo il nuovo stato
|
|
Else
|
|
SimulationStatus = SIM_ST.ST_STEP
|
|
' Aggiornamenti per bottone Play/Pause
|
|
m_bShowPlay = False
|
|
OnPropertyChanged("PlayPauseImage")
|
|
End If
|
|
End Sub
|
|
|
|
#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)
|
|
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)
|
|
StatusMsg = ""
|
|
If m_bShowPlay Then
|
|
' Disabilito check VMill
|
|
VMill_IsEnabled = False
|
|
' Aggiorno bottone
|
|
m_bShowPlay = False
|
|
OnPropertyChanged("PlayPauseImage")
|
|
' Eseguo
|
|
If m_nStatus = SIM_ST.ST_STOP Then
|
|
' Lancio simulazione
|
|
SimulationStatus = SIM_ST.ST_PLAY
|
|
ExecSim()
|
|
' Aggiorno bottone
|
|
m_bShowPlay = True
|
|
OnPropertyChanged("PlayPauseImage")
|
|
ElseIf m_nStatus = SIM_ST.ST_PAUSE Then
|
|
SimulationStatus = SIM_ST.ST_PLAY
|
|
End If
|
|
Else
|
|
' Aggiorno bottone
|
|
m_bShowPlay = 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
|
|
SimulationStatus = SIM_ST.ST_PAUSE
|
|
StatusMsg = EgtMsg(MSG_SIMULATION + 11) ' Pausa
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
|
|
#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)
|
|
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)
|
|
StatusMsg = ""
|
|
' Abilito check VMill
|
|
VMill_IsEnabled = True
|
|
' Se stato già stop, porto in home
|
|
If m_nStatus = SIM_ST.ST_STOP Then
|
|
' Mi riporto all'inizio
|
|
EgtSimStart()
|
|
EgtDraw()
|
|
' Aggiorno dati CNC
|
|
ShowCncData()
|
|
StatusMsg = EgtMsg(MSG_SIMULATION + 14) ' Home
|
|
Else
|
|
StatusMsg = EgtMsg(MSG_SIMULATION + 12) ' Stop
|
|
End If
|
|
' Aggiorno bottone
|
|
m_bShowPlay = True
|
|
OnPropertyChanged("PlayPauseImage")
|
|
' Imposto il nuovo stato
|
|
SimulationStatus = SIM_ST.ST_STOP
|
|
End Sub
|
|
|
|
|
|
#End Region ' StopCommand
|
|
|
|
#Region "GenerateCommand"
|
|
|
|
''' <summary>
|
|
''' Returns a command that create a new tool.
|
|
''' </summary>
|
|
Public ReadOnly Property GenerateCommand As ICommand
|
|
Get
|
|
If m_cmdGenerate Is Nothing Then
|
|
m_cmdGenerate = New RelayCommand(AddressOf Generate)
|
|
End If
|
|
Return m_cmdGenerate
|
|
End Get
|
|
End Property
|
|
|
|
''' <summary>
|
|
''' Creata the new tool. This method is invoked by the NewCommand.
|
|
''' </summary>
|
|
Public Sub Generate(ByVal param As Object)
|
|
' Recupero la fase corrente
|
|
Dim nPhase As Integer = EgtGetCurrPhase()
|
|
' Aggiorno le lavorazioni
|
|
If Not UpdateAllMachinings() Then
|
|
EgtSetCurrPhase(If(nPhase = 0, 1, nPhase), True)
|
|
Return
|
|
End If
|
|
' Eseguo
|
|
Dim sCurrFilePath As String = String.Empty
|
|
EgtGetCurrFilePath(sCurrFilePath)
|
|
If String.IsNullOrEmpty(sCurrFilePath) OrElse EgtGetModified() Then
|
|
' Il progetto deve essere salvato prima di poter essere generato. Vuoi farlo ?
|
|
If MessageBox.Show(EgtMsg(MSG_SIMULATION + 31), EgtMsg(MSG_SIMULATION + 15), MessageBoxButton.YesNo, MessageBoxImage.Warning) = MessageBoxResult.No Then
|
|
' Abbandono
|
|
Return
|
|
Else
|
|
' Lancio salvataggio
|
|
Application.Msn.NotifyColleagues(Application.SAVEPROJECT)
|
|
' Se non salvato, abbandono
|
|
If EgtGetModified() Then Return
|
|
End If
|
|
End If
|
|
Dim sCncFile As String = Path.ChangeExtension(sCurrFilePath, Nothing)
|
|
Dim sInfo As String = "EgtCAM5 - " & sCurrFilePath
|
|
If IniFile.m_bMachiningGroup Then
|
|
Dim sMGrpName As String = String.Empty
|
|
If EgtGetMachGroupName(EgtGetCurrMachGroup(), sMGrpName) Then
|
|
sCncFile &= "_" & sMGrpName & ".cnc"
|
|
sInfo &= "-" & sMGrpName
|
|
End If
|
|
Else
|
|
sCncFile &= ".cnc"
|
|
End If
|
|
If Not EgtGenerate(sCncFile, sInfo) Then
|
|
If EgtGetLastMachMgrErrorId() <> 0 Then
|
|
Dim sErr As String = EgtGetLastMachMgrErrorString()
|
|
MessageBox.Show(sErr, EgtMsg(MSG_SIMULATION + 5), MessageBoxButton.OK, MessageBoxImage.Exclamation)
|
|
Else
|
|
MessageBox.Show(EgtMsg(MSG_SIMULATION + 6), EgtMsg(MSG_SIMULATION + 5), MessageBoxButton.OK, MessageBoxImage.Error)
|
|
End If
|
|
Else
|
|
Application.Msn.NotifyColleagues(Application.NOTIFYSTATUSOUTPUT, EgtMsg(MSG_SIMULATION + 32))
|
|
End If
|
|
' Torno alla fase originale (o alla prima se non definita)
|
|
EgtSetCurrPhase(If(nPhase = 0, 1, nPhase), True)
|
|
End Sub
|
|
|
|
#End Region ' GenerateCommand
|
|
|
|
#End Region
|
|
|
|
#Region "METHODS"
|
|
|
|
Private Function UpdateAllMachinings() As Boolean
|
|
' Eseguo ricalcolo
|
|
Dim bModified As Boolean = EgtGetModified()
|
|
Dim sErr As String = String.Empty
|
|
Dim bOk As Boolean = EgtApplyAllMachinings(False, False, sErr)
|
|
' In caso di errori, li segnalo
|
|
If Not bOk Then
|
|
If Not String.IsNullOrEmpty(sErr) Then
|
|
MessageBox.Show(sErr, EgtMsg(MSG_SIMULATION + 5), MessageBoxButton.OK, MessageBoxImage.Exclamation)
|
|
Else
|
|
MessageBox.Show(EgtMsg(MSG_SIMULATION + 6), EgtMsg(MSG_SIMULATION + 5), MessageBoxButton.OK, MessageBoxImage.Error)
|
|
End If
|
|
End If
|
|
If Not bModified Then EgtResetModified()
|
|
Return bOk
|
|
End Function
|
|
|
|
Private Sub InitializeSimulation()
|
|
' Recupero la fase corrente
|
|
Dim nPhase As Integer = EgtGetCurrPhase()
|
|
' Aggiorno le lavorazioni
|
|
If Not UpdateAllMachinings() Then EgtSetCurrPhase(If(nPhase = 0, 1, nPhase), True)
|
|
' Costringo ad aggiornare UI
|
|
UpdateUI()
|
|
' Imposto stato corrente
|
|
SimulationStatus = SIM_ST.ST_STOP
|
|
m_bShowPlay = True
|
|
m_SliderX = GetPrivateProfileDouble(S_SIMUL, K_SLIDERX, 1)
|
|
Dim SliderVal As Double = GetPrivateProfileDouble(S_SIMUL, K_SLIDERVAL, 10)
|
|
SliderValue = SliderVal
|
|
' Gestione check VMill
|
|
If IsKeyEnabledVirtualMilling() And EgtUILib.GetPrivateProfileInt(S_VMILL, K_VM_ENABLE, 0, m_sCurrMachIniFilePath) <> 0 Then
|
|
VMill_Visibility = Visibility.Visible
|
|
VMill_IsEnabled = True
|
|
Dim bVal As Boolean
|
|
SetVMillActive(EgtGetInfo(EgtGetCurrMachGroup(), KEY_MCHGRP_VM, bVal) And bVal)
|
|
Else
|
|
VMill_Visibility = Visibility.Collapsed
|
|
VMill_IsEnabled = False
|
|
' Disabilito Vmill, ma inibisco dichiarazione progetto modificato
|
|
EgtDisableModified()
|
|
VMillActive = False
|
|
EgtEnableModified()
|
|
End If
|
|
' Inizio simulazione
|
|
If Not EgtSimStart() Then
|
|
If EgtGetLastMachMgrErrorId() <> 0 Then
|
|
Dim sErr As String = EgtGetLastMachMgrErrorString()
|
|
MessageBox.Show(sErr, EgtMsg(MSG_SIMULATION + 5), MessageBoxButton.OK, MessageBoxImage.Exclamation) '.... - ERRORE
|
|
Else
|
|
MessageBox.Show(EgtMsg(MSG_MESSAGEBOX + 10), EgtMsg(MSG_SIMULATION + 5), MessageBoxButton.OK, MessageBoxImage.Error) 'Errore sconosciuto - ERRORE
|
|
End If
|
|
End If
|
|
' Aggiorno visualizzazione dati macchina
|
|
ShowCncData()
|
|
StatusMsg = EgtMsg(MSG_SIMULATION + 14) ' Home
|
|
End Sub
|
|
|
|
Private Sub CloseSimulation()
|
|
StatusMsg = ""
|
|
' Mi assicuro di terminare la simulazione
|
|
ResetSimulation()
|
|
End Sub
|
|
|
|
Private Sub ResetSimulation()
|
|
' Termino la simulazione
|
|
SimulationStatus = 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)
|
|
End Sub
|
|
|
|
Private Sub ExecSim()
|
|
m_bSimExecuting = True
|
|
IniFile.m_bSimulExecuting = True
|
|
Application.Msn.NotifyColleagues(Application.SETDRAWISENABLED, False)
|
|
Application.Msn.NotifyColleagues(Application.OPERATIONVIEWEXPANDERISENABLED, False)
|
|
Application.Msn.NotifyColleagues(Application.MACHGROUPSISENABLED, False)
|
|
EgtSimStart(False)
|
|
EgtSimSetStep(SliderValue * m_SliderX)
|
|
Dim nShowDataCounter As Integer = 0
|
|
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
|
|
SimulationStatus = SIM_ST.ST_PAUSE
|
|
StatusMsg = EgtMsg(MSG_SIMULATION + 11) ' Pausa
|
|
' Aggiornamenti per bottone Play/Pause
|
|
m_bShowPlay = True
|
|
OnPropertyChanged("PlayPauseImage")
|
|
End If
|
|
' Se movimento non riuscito
|
|
Else
|
|
SimulationStatus = SIM_ST.ST_STOP
|
|
' Aggiornamenti per bottone Play/Pause
|
|
m_bShowPlay = True
|
|
OnPropertyChanged("PlayPauseImage")
|
|
' Abilito check VMill
|
|
VMill_IsEnabled = True
|
|
Select Case nMove
|
|
Case MCH_SIM.END_
|
|
StatusMsg = EgtMsg(MSG_SIMULATION + 1) 'Simulazione completata
|
|
Case MCH_SIM.OUTSTROKE
|
|
Dim sInfo As String = String.Empty
|
|
EgtGetOutstrokeInfo(sInfo)
|
|
MessageBox.Show(EgtMsg(MSG_SIMULATION + 2) & " " & sInfo, EgtMsg(MSG_SIMULATION + 5), MessageBoxButton.OK, MessageBoxImage.Stop) 'Extracorsa ...
|
|
Case MCH_SIM.DIR_ERR
|
|
MessageBox.Show(EgtMsg(MSG_SIMULATION + 3), EgtMsg(MSG_SIMULATION + 5), MessageBoxButton.OK, MessageBoxImage.Stop) 'Direzione utensile irraggiungibile
|
|
Case Else
|
|
MessageBox.Show(EgtMsg(MSG_SIMULATION + 4), EgtMsg(MSG_SIMULATION + 5), MessageBoxButton.OK, MessageBoxImage.Stop) 'Errore
|
|
End Select
|
|
End If
|
|
' Aggiorno stato visualizzazione macchina (dipende anche da utensile)
|
|
UpdateMachView()
|
|
' Aggiorno visualizzazione
|
|
EgtDraw()
|
|
' Aggiorno dati CNC
|
|
If nShowDataCounter = 5 Or SimulationStatus = SIM_ST.ST_PAUSE Or SimulationStatus = SIM_ST.ST_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(4)
|
|
End If
|
|
' Costringo ad aggiornare UI
|
|
UpdateUI()
|
|
End While
|
|
m_bSimExecuting = False
|
|
IniFile.m_bSimulExecuting = False
|
|
Application.Msn.NotifyColleagues(Application.SETDRAWISENABLED, True)
|
|
Application.Msn.NotifyColleagues(Application.OPERATIONVIEWEXPANDERISENABLED, True)
|
|
Application.Msn.NotifyColleagues(Application.MACHGROUPSISENABLED, True)
|
|
End Sub
|
|
|
|
Private 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).Value = 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
|
|
If dSpeed > 1 Then
|
|
SValue = "S" & DoubleToString(dSpeed, 0)
|
|
Else
|
|
SValue = ""
|
|
End If
|
|
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
|
|
|
|
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 |