Files
EgtCAM5/ProjectPage/MachGroupPanel/MachGroupPanelViewModel.vb
T
Emmanuele Sassi dffe9de64e EgtCAM5 :
- Migliorie SetUp.
- Migliorie simulazione.
2017-01-27 18:33:56 +00:00

223 lines
9.0 KiB
VB.net

Imports System.Collections.ObjectModel
Imports System.IO
Imports EgtUILib
Namespace EgtCAM5
Public Class MachGroupPanelViewModel
Inherits ViewModelBase
#Region "FIELDS & PROPERTIES"
Private m_MachGroupList As New ObservableCollection(Of String)
Public Property MachGroupList As ObservableCollection(Of String)
Get
Return m_MachGroupList
End Get
Set(value As ObservableCollection(Of String))
If value IsNot m_MachGroupList Then
m_MachGroupList = value
End If
End Set
End Property
Private m_SelectedMachGroup As String
Public Property SelectedMachGroup As String
Get
Return m_SelectedMachGroup
End Get
Set(value As String)
m_SelectedMachGroup = value
OnPropertyChanged("SelectedMachGroup")
End Set
End Property
' Definizione comandi
Private m_cmdSetCurrMachGroup As ICommand
Private m_cmdAddMachGroup As ICommand
Private m_cmdRemoveMachGroup As ICommand
#End Region ' FIELDS & PROPERTIES
#Region "CONSTRUCTOR"
Sub New()
Application.Msn.Register(Application.INITIALIZEMACHGROUPS, Sub()
InitializeMachGroups()
End Sub)
End Sub
#End Region ' CONSTRUCTOR
#Region "METHODS"
Private Sub InitializeMachGroups()
Dim bOk As Boolean
Dim nId = EgtGetFirstMachGroup()
If nId <> GDB_ID.NULL Then
bOk = EgtSetCurrMachGroup(nId)
Else
bOk = AddNewMachGroup()
End If
LoadMachGroups()
SelectedMachGroup = MachGroupList(0)
Application.Msn.NotifyColleagues(Application.MACHGROUPSRESULT, bOk)
End Sub
Private Sub LoadMachGroups()
' Pulisco la lista
MachGroupList.Clear()
' Carico i gruppi di lavorazione nella lista
Dim nId = EgtGetFirstMachGroup()
While nId <> GDB_ID.NULL
Dim sName As String = String.Empty
EgtGetMachGroupName(nId, sName)
MachGroupList.Add(sName)
nId = EgtGetNextMachGroup(nId)
End While
End Sub
Private Function AddNewMachGroup() As Boolean
Dim sNewMachName As String = "Mach_1"
EgtGetMachGroupNewName(sNewMachName)
Dim bOk As Boolean = (EgtAddMachGroup(sNewMachName) <> GDB_ID.NULL)
Dim sInitScriptPath As String = String.Empty
Dim sDefaultSetUpPath As String = String.Empty
' leggo nome script di disposizione automatica
EgtUILib.GetPrivateProfileString(S_DISPOSITION, K_INITSCRIPT, "", sInitScriptPath, IniFile.m_sCurrMachIniFilePath)
' leggo nome attrezzaggio di default
EgtUILib.GetPrivateProfileString(S_DISPOSITION, K_ACTIVEDEFAULT, "", sDefaultSetUpPath, IniFile.m_sCurrMachIniFilePath)
' se è attivo, uso lo script di disposizione
If bOk AndAlso OptionModule.m_bUseDispositionScript And Not String.IsNullOrEmpty(sInitScriptPath) Then
sInitScriptPath = IniFile.m_sCurrMachScriptsDirPath & "\" & sInitScriptPath
If Not File.Exists(sInitScriptPath) AndAlso Not EgtLuaExecFile(sInitScriptPath) Then
EgtOutLog("Error executing disposition init script " & sInitScriptPath)
MessageBox.Show(EgtMsg(MSG_DISPOSITIONERRORS + 1), EgtMsg(MSG_DISPOSITIONERRORS + 2) & " " & sInitScriptPath, MessageBoxButton.OK, MessageBoxImage.Exclamation)
End If
End If
' se è attiva l'opzione, rendo corrente l'attrezzaggio di default
If bOk AndAlso MachOptionModule.m_bIsActiveDefaultSetUp And Not String.IsNullOrEmpty(sInitScriptPath) Then
sDefaultSetUpPath = IniFile.m_sCurrMachScriptsDirPath & "\" & sDefaultSetUpPath
'If Not File.Exists(sDefaultSetUpPath) AndAlso Not EgtLuaExecFile(sInitScriptPath) Then
' EgtOutLog("Error executing disposition init script " & sInitScriptPath)
' MessageBox.Show(EgtMsg(MSG_DISPOSITIONERRORS + 1), EgtMsg(MSG_DISPOSITIONERRORS + 2) & " " & sInitScriptPath, MessageBoxButton.OK, MessageBoxImage.Exclamation)
'End If
End If
Return bOk
End Function
#End Region
#Region "COMMANDS"
#Region "SetCurrMachGroupCommand"
''' <summary>
''' Returns a command that set the selected MachGroup as the Current one.
''' </summary>
Public ReadOnly Property SetCurrMachGroupCommand As ICommand
Get
If m_cmdSetCurrMachGroup Is Nothing Then
m_cmdSetCurrMachGroup = New RelayCommand(AddressOf SetCurrMachGroup)
End If
Return m_cmdSetCurrMachGroup
End Get
End Property
Public Sub SetCurrMachGroup(ByVal param As Object)
EgtSetCurrMachGroup(EgtGetMachGroupId(DirectCast(param, String)))
EgtDraw()
Application.Msn.NotifyColleagues(Application.LOADOPERATIONLIST, -1)
Application.Msn.NotifyColleagues(Application.UPDATECURRENTMACHINE)
End Sub
#End Region ' SetCurrMachGroupCommand
#Region "AddMachGroupCommand"
''' <summary>
''' Returns a command that set the selected MachGroup as the Current one.
''' </summary>
Public ReadOnly Property AddMachGroupCommand As ICommand
Get
If m_cmdAddMachGroup Is Nothing Then
m_cmdAddMachGroup = New RelayCommand(AddressOf AddMachGroup)
End If
Return m_cmdAddMachGroup
End Get
End Property
Public Sub AddMachGroup()
If AddNewMachGroup() Then
Dim sMachName As String = String.Empty
EgtGetMachGroupName(EgtGetCurrMachGroup(), sMachName)
MachGroupList.Add(sMachName)
SelectedMachGroup = sMachName
EgtDraw()
Application.Msn.NotifyColleagues(Application.LOADOPERATIONLIST, -1)
Application.Msn.NotifyColleagues(Application.UPDATECURRENTMACHINE)
End If
End Sub
#End Region ' AddMachGroupCommand
#Region "RemoveMachGroupCommand"
''' <summary>
''' Returns a command that set the selected MachGroup as the Current one.
''' </summary>
Public ReadOnly Property RemoveMachGroupCommand As ICommand
Get
If m_cmdRemoveMachGroup Is Nothing Then
m_cmdRemoveMachGroup = New RelayCommand(AddressOf RemoveMachGroup)
End If
Return m_cmdRemoveMachGroup
End Get
End Property
Public Sub RemoveMachGroup()
' Calcolo indice del gruppo da cancellare
Dim nSelectedMachGroupIndex As Integer = MachGroupList.IndexOf(SelectedMachGroup)
If nSelectedMachGroupIndex = 0 And MachGroupList.Count = 1 Then
' chiedo conferma prima di resettare il gruppo di lavorazione
Select Case MessageBox.Show(EgtMsg(MSG_MACHGROUP + 1), "", MessageBoxButton.YesNo, MessageBoxImage.Question)
Case MessageBoxResult.Yes
' cancello il gruppo corrente e ne creo uno nuovo con lo stesso nome
EgtRemoveMachGroup(EgtGetMachGroupId(MachGroupList(nSelectedMachGroupIndex)))
EgtAddMachGroup(SelectedMachGroup)
EgtDraw()
Case MessageBoxResult.No
Return
End Select
Else
' chiedo conferma prima di cancellare il gruppo di lavorazione
Select Case MessageBox.Show(EgtMsg(MSG_MACHGROUP + 2), "", MessageBoxButton.YesNo, MessageBoxImage.Question)
Case MessageBoxResult.Yes
If nSelectedMachGroupIndex = 0 And MachGroupList.Count > 1 Then
' rendo corrente il gruppo di lavorazione successivo a quello da cancellare
EgtSetCurrMachGroup(EgtGetMachGroupId(MachGroupList(nSelectedMachGroupIndex + 1)))
SelectedMachGroup = MachGroupList(nSelectedMachGroupIndex + 1)
ElseIf nSelectedMachGroupIndex > 0 Then
' rendo corrente il gruppo di lavorazione precedente a quello da cancellare
EgtSetCurrMachGroup(EgtGetMachGroupId(MachGroupList(nSelectedMachGroupIndex - 1)))
SelectedMachGroup = MachGroupList(nSelectedMachGroupIndex - 1)
End If
EgtDraw()
' cancello quello selezionato
EgtRemoveMachGroup(EgtGetMachGroupId(MachGroupList(nSelectedMachGroupIndex)))
' aggiorno la lista dei gruppi
MachGroupList.RemoveAt(nSelectedMachGroupIndex)
Case MessageBoxResult.No
Return
End Select
End If
End Sub
#End Region ' RemoveMachGroupCommand
#End Region ' COMMANDS
End Class
End Namespace