507 lines
16 KiB
VB.net
507 lines
16 KiB
VB.net
Imports System.Collections.ObjectModel
|
|
Imports System.IO
|
|
Imports EgtUILib
|
|
Imports EgtWPFLib5
|
|
Imports EgtBEAMWALL.Core
|
|
|
|
Public Class ConfigurationPageVM
|
|
Inherits VMBase
|
|
|
|
' flag modifica parametri Macchina
|
|
Friend bModifyMachParam As Boolean
|
|
|
|
' Definizione comandi
|
|
Private m_cmdSave As ICommand
|
|
|
|
Private m_ConfigMachTableList As New ObservableCollection(Of MachTable)
|
|
Public Property ConfigMachTableList As ObservableCollection(Of MachTable)
|
|
Get
|
|
Return m_ConfigMachTableList
|
|
End Get
|
|
Set(value As ObservableCollection(Of MachTable))
|
|
m_ConfigMachTableList = value
|
|
End Set
|
|
End Property
|
|
|
|
Public ReadOnly Property Custom_Visibility As Visibility
|
|
Get
|
|
If QBTLParamVMList(0).bIsP Then
|
|
Return Visibility.Collapsed
|
|
Else
|
|
Return Visibility.Visible
|
|
End If
|
|
End Get
|
|
End Property
|
|
|
|
Private m_SelGRPType As GRPType
|
|
Public Property SelGRPType As Integer
|
|
Get
|
|
Return m_SelGRPType
|
|
End Get
|
|
Set(value As Integer)
|
|
m_SelGRPType = value
|
|
QBTLParamVMList.Clear()
|
|
Select Case m_SelGRPType
|
|
Case 0
|
|
m_PRCList = L_PRCList
|
|
Case 1
|
|
m_PRCList = T_PRCList
|
|
End Select
|
|
m_nSelPRC = Nothing
|
|
NotifyPropertyChanged(NameOf(PRCList))
|
|
NotifyPropertyChanged(NameOf(nSelPRC))
|
|
End Set
|
|
End Property
|
|
|
|
Private m_L_PRCList As New ObservableCollection(Of PRC)
|
|
Public ReadOnly Property L_PRCList As ObservableCollection(Of PRC)
|
|
Get
|
|
Return m_L_PRCList
|
|
End Get
|
|
End Property
|
|
|
|
Private m_T_PRCList As New ObservableCollection(Of PRC)
|
|
Public ReadOnly Property T_PRCList As ObservableCollection(Of PRC)
|
|
Get
|
|
Return m_T_PRCList
|
|
End Get
|
|
End Property
|
|
|
|
' lista dei parametri Q di un Process
|
|
Protected m_QBTLParamVMList As New ObservableCollection(Of BTLParamVM)
|
|
Public Property QBTLParamVMList As ObservableCollection(Of BTLParamVM)
|
|
Get
|
|
Return m_QBTLParamVMList
|
|
End Get
|
|
Set(value As ObservableCollection(Of BTLParamVM))
|
|
m_QBTLParamVMList = value
|
|
End Set
|
|
End Property
|
|
|
|
Private m_PRCList As New ObservableCollection(Of PRC)
|
|
Public ReadOnly Property PRCList As ObservableCollection(Of PRC)
|
|
Get
|
|
Return m_PRCList
|
|
End Get
|
|
End Property
|
|
|
|
Private m_nSelPRC As PRC = Nothing
|
|
Public Property nSelPRC As PRC
|
|
Get
|
|
Return m_nSelPRC
|
|
End Get
|
|
Set(value As PRC)
|
|
If value IsNot m_nSelPRC Then
|
|
m_nSelPRC = value
|
|
' carico la lista dei parametri Q in base al Process selezionato
|
|
If Not IsNothing(QBTLParamVMList) Then
|
|
QBTLParamVMList.Clear()
|
|
End If
|
|
For Each QBTLParam In nSelPRC.QBTLParamVMList
|
|
QBTLParamVMList.Add(QBTLParam)
|
|
Next
|
|
NotifyPropertyChanged(NameOf(QBTLParamVMList))
|
|
End If
|
|
End Set
|
|
End Property
|
|
|
|
#Region "Messages"
|
|
|
|
Public ReadOnly Property NAM_Msg As String
|
|
Get
|
|
Return "Nome"
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property Description_Msg As String
|
|
Get
|
|
Return "Descrizione"
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property Default_Msg As String
|
|
Get
|
|
Return "Default"
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property Min_Msg As String
|
|
Get
|
|
Return "Min"
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property Max_Msg As String
|
|
Get
|
|
Return "Max"
|
|
End Get
|
|
End Property
|
|
|
|
#End Region ' Messages
|
|
|
|
#Region "Constructor"
|
|
|
|
Sub New()
|
|
' imposto riferimento in Map
|
|
Map.SetRefConfigurationPageVM(Me)
|
|
' assegno le liste dei parametri della macchina corrente alla ConfigMachTableList alla pagina di Configurazione
|
|
ConfigMachTableList = CurrentMachine.MachTableList
|
|
' carico i parametri Q dei Process letti dall'ini
|
|
GetQParamsList()
|
|
' inizializzo la lista dei Process settando il tipo di GRP a 0
|
|
SelGRPType = 0
|
|
End Sub
|
|
|
|
#End Region ' Constructor
|
|
|
|
#Region "SaveCommand"
|
|
|
|
''' <summary>
|
|
''' Returns a command that do Save.
|
|
''' </summary>
|
|
Public ReadOnly Property SaveCommand As ICommand
|
|
Get
|
|
If m_cmdSave Is Nothing Then
|
|
m_cmdSave = New Command(AddressOf Save)
|
|
End If
|
|
Return m_cmdSave
|
|
End Get
|
|
End Property
|
|
|
|
''' <summary>
|
|
''' Execute the Save. This method is invoked by the SaveCommand.
|
|
''' </summary>
|
|
Public Sub Save()
|
|
WriteMachParams()
|
|
WriteProcessParams(L_PRCList.ToList())
|
|
WriteProcessParams(T_PRCList.ToList())
|
|
End Sub
|
|
|
|
#End Region ' SaveCommand
|
|
|
|
#Region "Methods"
|
|
|
|
' funzione che scrive i parametri modificati sul file INI
|
|
Public Sub WriteMachParams()
|
|
For Each MachTableItem In ConfigMachTableList
|
|
For Each MachParamItem In MachTableItem.MachParamList
|
|
If MachParamItem.IsModified Then
|
|
Dim sMachParamType As String = String.Empty
|
|
Select Case MachParamItem.nType
|
|
Case MachParamType.DOUBLE_
|
|
sMachParamType = "d"
|
|
Case MachParamType.STRING_
|
|
sMachParamType = "s"
|
|
Case MachParamType.LENGTH
|
|
sMachParamType = "l"
|
|
End Select
|
|
Dim MachParamString As String = sMachParamType & "," & MachParamItem.sName & "," & MachParamItem.sValue & "," & MachParamItem.sDescription
|
|
Dim bOk = WriteMachPrivateProfileString(MachParamItem.nParentTable, MachParamItem.nParamIndex, MachParamString)
|
|
If Not bOk Then
|
|
MessageBox.Show("Errore nella scrittura di un parametro Macchina", "Error")
|
|
Return
|
|
End If
|
|
MachParamItem.IsModifiedReset()
|
|
End If
|
|
Next
|
|
Next
|
|
End Sub
|
|
|
|
' funzione che verifica la modifica dei parametri e ne chiede il salvataggio
|
|
Friend Function VerifyConfigPageModification() As Boolean
|
|
For Each MachTableItem In ConfigMachTableList
|
|
For Each MachParamItem In MachTableItem.MachParamList
|
|
If MachParamItem.IsModified Then
|
|
If MessageBox.Show("Salvare le modifiche apportate ai parametri Macchina?", "", MessageBoxButton.YesNo, MessageBoxImage.Question) = MessageBoxResult.Yes Then
|
|
' salvo parametri Macchina
|
|
Save()
|
|
Else
|
|
' se da non salvare
|
|
CreateMachParams()
|
|
Return False
|
|
End If
|
|
End If
|
|
Next
|
|
Next
|
|
Return True
|
|
End Function
|
|
|
|
' funzione che verifica l'inserimento della password quando si edita un parametro Macchina
|
|
Friend Function VerifyConfigPagePassword() As Boolean
|
|
' Display message, title, and default value.
|
|
Dim sPwdInput = InputBox("Inserire Password: ", "Richiesta Pwd")
|
|
' Lettura PWD dall'INI e confronto
|
|
Dim sPwdIni As String = String.Empty
|
|
If GetMainPrivateProfileString(S_MACH, K_PASSWORD, "", sPwdIni) <> 0 Then
|
|
If sPwdIni = sPwdInput Then Return True
|
|
End If
|
|
Return False
|
|
End Function
|
|
|
|
Public Sub GetQParamsList()
|
|
' carico lista process
|
|
Dim TempPRCList As New ObservableCollection(Of Integer)
|
|
' prima cerco i process L
|
|
Dim GRPType As Integer = 0
|
|
GetBeamPrivateProfileProcessList(GRPType, TempPRCList)
|
|
m_L_PRCList.Clear()
|
|
For Each PRC In TempPRCList
|
|
' leggo gruppi
|
|
Dim GRPList As New ObservableCollection(Of Integer)
|
|
GetBeamPrivateProfileGRPList(GRPType, PRC, GRPList)
|
|
m_L_PRCList.Add(New PRC(If(GRPList.Count > 0, GRPList(0), GRPType), PRC, GetBeamPrivateProfileName(GRPType, PRC), CreateProcessParams(GRPType, PRC, False)))
|
|
Next
|
|
' ora cerco i process T
|
|
GRPType = 1
|
|
GetBeamPrivateProfileProcessList(GRPType, TempPRCList)
|
|
m_T_PRCList.Clear()
|
|
For Each PRC In TempPRCList
|
|
' leggo gruppi
|
|
Dim GRPList As New ObservableCollection(Of Integer)
|
|
GetBeamPrivateProfileGRPList(GRPType, PRC, GRPList)
|
|
m_T_PRCList.Add(New PRC(If(GRPList.Count > 0, GRPList(0), GRPType), PRC, GetBeamPrivateProfileName(GRPType, PRC), CreateProcessParams(GRPType, PRC, False)))
|
|
Next
|
|
End Sub
|
|
|
|
' funzione che crea l'elenco dei parametri P o Q di un Process
|
|
Public Function CreateProcessParams(GRPType As Integer, PRC As Integer, IsP As Boolean)
|
|
Dim ParamIndex As Integer = 1
|
|
Dim TempList As New List(Of BTLParamVM)
|
|
Dim NewBTLParam As BTLParamM = Nothing
|
|
' leggo tutti i parametri P o Q del Process
|
|
ParamIndex = 1
|
|
TempList = New List(Of BTLParamVM)
|
|
While BTLIniFile.GetBeamPrivateProfileParam(GRPType, PRC, IsP, ParamIndex, Nothing, NewBTLParam)
|
|
TempList.Add(New BTLParamVM(NewBTLParam))
|
|
ParamIndex += 1
|
|
End While
|
|
Return TempList
|
|
End Function
|
|
|
|
' funzione che scrive l'elenco dei parametri P o Q di un Process
|
|
Public Sub WriteProcessParams(PRCList As List(Of PRC))
|
|
For Each PRCItem In PRCList
|
|
Dim nPRCParamIndex As Integer = 1
|
|
For Each PRCParam In PRCItem.QBTLParamVMList
|
|
If PRCParam.bIsModified Then
|
|
' costruisco la stringa da scrivere nel parametro
|
|
Dim sType As String = ""
|
|
If PRCParam.nType = 1 Then
|
|
sType = "d"
|
|
ElseIf PRCParam.nType = 4 Then
|
|
sType = "l"
|
|
End If
|
|
Dim sPRCParam As String = sType & "," & If(PRCParam.bIsP, "P", "Q") & PRCParam.nId.ToString("D2") & "," & PRCParam.sMin & "," & PRCParam.sMax & "," & PRCParam.sDefault & "," & PRCParam.sDescription
|
|
WritePrivateProfileString(PRCItem.nGRP & "." & PRCItem.nPRC, If(PRCParam.bIsP, "P", "Q") & nPRCParamIndex, sPRCParam, m_sBTLIniFile)
|
|
End If
|
|
nPRCParamIndex += 1
|
|
Next
|
|
Next
|
|
End Sub
|
|
|
|
#End Region ' Methods
|
|
|
|
End Class
|
|
|
|
Public Class MachParam
|
|
Inherits VMBase
|
|
|
|
' table a cui appartiene il parametro
|
|
Private m_nParentTable As Integer
|
|
Friend ReadOnly Property nParentTable As Integer
|
|
Get
|
|
Return m_nParentTable
|
|
End Get
|
|
End Property
|
|
|
|
' indice del parametro
|
|
Private m_nParamIndex As Integer
|
|
Friend ReadOnly Property nParamIndex As Integer
|
|
Get
|
|
Return m_nParamIndex
|
|
End Get
|
|
End Property
|
|
|
|
' tipo della variabile
|
|
Private m_nType As MachParamType
|
|
Friend ReadOnly Property nType As MachParamType
|
|
Get
|
|
Return m_nType
|
|
End Get
|
|
End Property
|
|
|
|
' parametri da struttura
|
|
Private m_sName As String
|
|
Public Property sName As String
|
|
Get
|
|
Return m_sName
|
|
End Get
|
|
Set(value As String)
|
|
m_sName = value
|
|
End Set
|
|
End Property
|
|
|
|
' parametri da geometria
|
|
Private m_IsModifiedValue As Boolean = False
|
|
Private m_dValue As Double
|
|
Private m_sValue As String
|
|
Public Property sValue As String
|
|
Get
|
|
Select Case nType
|
|
Case MachParamType.DOUBLE_
|
|
Return DoubleToString(m_dValue, 3)
|
|
Case MachParamType.LENGTH
|
|
Return LenToString(m_dValue, 3)
|
|
Case Else ' stringhe
|
|
Return m_sValue
|
|
End Select
|
|
Return If(nType = MachParamType.LENGTH, LenToString(m_dValue, 3), DoubleToString(m_dValue, 3))
|
|
End Get
|
|
Set(value As String)
|
|
Dim dNewValue As Double
|
|
' verifico se valore immesso è diverso dall'originale
|
|
If nParentTable > 0 Then
|
|
Dim sOrigValue As String = String.Empty
|
|
Dim dOrigValue As Double
|
|
MachParamIniFile.GetMachPrivateProfileParamValue(nParentTable, nParamIndex, sOrigValue)
|
|
' trasformo valori
|
|
Select Case nType
|
|
Case MachParamType.DOUBLE_
|
|
StringToDouble(value, dNewValue)
|
|
StringToDouble(sOrigValue, dOrigValue)
|
|
Case MachParamType.LENGTH
|
|
StringToLen(value, dNewValue)
|
|
StringToLen(sOrigValue, dOrigValue)
|
|
Case Else
|
|
' per string non faccio nulla
|
|
End Select
|
|
m_IsModifiedValue = dNewValue <> dOrigValue
|
|
End If
|
|
' se valore immesso è diverso e password non inserita
|
|
If m_IsModifiedValue AndAlso Not Map.refConfigurationPageVM.bModifyMachParam Then
|
|
Map.refConfigurationPageVM.bModifyMachParam = Map.refConfigurationPageVM.VerifyConfigPagePassword()
|
|
If Not Map.refConfigurationPageVM.bModifyMachParam Then
|
|
NotifyPropertyChanged("sValue")
|
|
m_IsModifiedValue = False
|
|
Return
|
|
End If
|
|
End If
|
|
|
|
Select Case nType
|
|
Case MachParamType.DOUBLE_, MachParamType.LENGTH
|
|
UpdateParamValue(dNewValue, "")
|
|
Case Else
|
|
UpdateParamValue(0, value)
|
|
End Select
|
|
End Set
|
|
End Property
|
|
Public Property dValue As Double
|
|
Get
|
|
Return m_dValue
|
|
End Get
|
|
Set(value As Double)
|
|
m_dValue = value
|
|
NotifyPropertyChanged("sValue")
|
|
End Set
|
|
End Property
|
|
|
|
' descrizione del parametro
|
|
Private m_sDescription As String
|
|
Public Property sDescription As String
|
|
Get
|
|
Return m_sDescription
|
|
End Get
|
|
Set(value As String)
|
|
m_sDescription = value
|
|
End Set
|
|
End Property
|
|
|
|
Private Sub StdInit(nParentTable As Integer, nParamIndex As Integer, Type As MachParamType, sName As String, sDescription As String)
|
|
m_nParentTable = nParentTable
|
|
m_nParamIndex = nParamIndex
|
|
m_nType = Type
|
|
m_sName = sName
|
|
Dim nDescription As Integer
|
|
If IsNumeric(sDescription) AndAlso Integer.TryParse(sDescription, nDescription) Then
|
|
m_sDescription = EgtMsg(sDescription)
|
|
Else
|
|
m_sDescription = sDescription
|
|
End If
|
|
End Sub
|
|
|
|
' new per double e length
|
|
Sub New(nParentTable As Integer, nParamIndex As Integer, nType As MachParamType, sParamName As String, dValue As Double, sDescription As String)
|
|
StdInit(nParentTable, nParamIndex, nType, sParamName, sDescription)
|
|
m_dValue = dValue 'sValue = DoubleToString(dValue, 3)
|
|
End Sub
|
|
|
|
' new per stringhe
|
|
Sub New(nParentTable As Integer, nParamIndex As Integer, nType As MachParamType, sParamName As String, sDescription As String)
|
|
StdInit(nParentTable, nParamIndex, nType, sParamName, sDescription)
|
|
End Sub
|
|
|
|
' new per parametro vuoto
|
|
Sub New(nType As MachParamType, nParamIndex As Integer, sParamName As String)
|
|
StdInit(Nothing, nParamIndex, nType, sParamName, "")
|
|
End Sub
|
|
|
|
Friend Sub UpdateParamValue(dNewValue As Double, sNewValue As String, Optional bDraw As Boolean = True)
|
|
Select Case nType
|
|
Case MachParamType.DOUBLE_, MachParamType.LENGTH
|
|
m_dValue = dNewValue
|
|
Case MachParamType.STRING_
|
|
m_sValue = sNewValue
|
|
End Select
|
|
End Sub
|
|
|
|
Public ReadOnly Property IsModified() As Boolean
|
|
Get
|
|
Return m_IsModifiedValue
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub IsModifiedReset()
|
|
m_IsModifiedValue = False
|
|
End Sub
|
|
|
|
End Class
|
|
|
|
Public Class MachTable
|
|
Inherits VMBase
|
|
|
|
' nome della table
|
|
Private m_sName As String
|
|
Public Property sName As String
|
|
Get
|
|
Return m_sName
|
|
End Get
|
|
Set(value As String)
|
|
m_sName = value
|
|
End Set
|
|
End Property
|
|
|
|
Private m_MachParamList As New ObservableCollection(Of MachParam)
|
|
Public Property MachParamList As ObservableCollection(Of MachParam)
|
|
Get
|
|
Return m_MachParamList
|
|
End Get
|
|
Set(value As ObservableCollection(Of MachParam))
|
|
m_MachParamList = value
|
|
End Set
|
|
End Property
|
|
|
|
Sub New(Name As String, ParamList As ObservableCollection(Of MachParam))
|
|
sName = Name
|
|
MachParamList = ParamList
|
|
End Sub
|
|
|
|
End Class
|
|
|
|
' Tipo parametro nel file di configurazione Macchina
|
|
Public Enum MachParamType As Integer
|
|
DOUBLE_ = 1
|
|
STRING_ = 2
|
|
COMBO = 3
|
|
LENGTH = 4
|
|
CHECKBOX = 5
|
|
End Enum
|