Files
egtbeamwall/EgtBEAMWALL.ViewerOptimizer/ConfigurationPage/ConfigurationPageVM.vb
T
2021-12-13 11:06:34 +01:00

1147 lines
44 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
Public ReadOnly Property MachinePanelVM As MachinePanelVM
Get
Return Map.refMachinePanelVM
End Get
End Property
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
' lista dei parametri Q di un Process
Private m_QBTLParamVMList_View As CollectionView = Nothing
Protected m_QBTLParamVMList As New ObservableCollection(Of QBTLParamVM)
Public Property QBTLParamVMList As ObservableCollection(Of QBTLParamVM)
Get
Return m_QBTLParamVMList
End Get
Set(value As ObservableCollection(Of QBTLParamVM))
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_LanguageList As New ObservableCollection(Of Language)
Public ReadOnly Property LanguageList As ObservableCollection(Of Language)
Get
Return m_LanguageList
End Get
End Property
Private m_UnitMeasureList As List(Of String) = New List(Of String)({"inch", "mm"})
Public ReadOnly Property UnitMeasureList As List(Of String)
Get
Return m_UnitMeasureList
End Get
End Property
Private m_SelectedLanguage As Language
Public Property SelectedLanguage As Language
Get
Return m_SelectedLanguage
End Get
Set(value As Language)
If value IsNot m_SelectedLanguage Then
m_SelectedLanguage = value
End If
End Set
End Property
Public Property SelMeasureUnit As Integer
Get
Return If(EgtUiUnitsAreMM(), MeasureUnitOpt.MM, MeasureUnitOpt.INCH)
End Get
Set(value As Integer)
' salvo unità di misura precedente
Dim PrevMeasureUnit As MeasureUnitOpt = If(EgtUiUnitsAreMM(), MeasureUnitOpt.MM, MeasureUnitOpt.INCH)
If value <> PrevMeasureUnit Then
' cambio unità di misura
EgtSetUiUnits(DirectCast(value, MeasureUnitOpt) = MeasureUnitOpt.MM)
End If
End Set
End Property
Private m_SectionTime As Double
Public Property SectionTime As String
Get
Return DoubleToString(m_SectionTime, 5)
End Get
Set(value As String)
Dim dVal As Double = 0
If StringToDouble(value, dVal) AndAlso dVal > 0 Then
m_SectionTime = dVal
End If
End Set
End Property
Private m_PartTime As Double
Public Property PartTime As String
Get
Return DoubleToString(m_PartTime, 5)
End Get
Set(value As String)
Dim dVal As Double = 0
If StringToDouble(value, dVal) AndAlso dVal > 0 Then
m_PartTime = dVal
End If
End Set
End Property
' lista delle colonne con le relative proprietà della DataGrid
Private m_DGColumnsList_View As CollectionView = Nothing
Protected m_DGColumnsList As New ObservableCollection(Of IniDataGridColumn)
Public Property DGColumnsList As ObservableCollection(Of IniDataGridColumn)
Get
Return m_DGColumnsList
End Get
Set(value As ObservableCollection(Of IniDataGridColumn))
m_DGColumnsList = value
End Set
End Property
#Region "Messages"
Public ReadOnly Property L_Msg As String
Get
Return EgtMsg(61803)
End Get
End Property
Public ReadOnly Property T_Msg As String
Get
Return EgtMsg(61804)
End Get
End Property
Public ReadOnly Property PRC_Msg As String
Get
Return EgtMsg(61805)
End Get
End Property
Public ReadOnly Property Type_Msg As String
Get
Return EgtMsg(61850)
End Get
End Property
Public ReadOnly Property NAM_Msg As String
Get
Return EgtMsg(61608)
End Get
End Property
Public ReadOnly Property Description_Msg As String
Get
Return EgtMsg(61603)
End Get
End Property
Public ReadOnly Property Default_Msg As String
Get
Return EgtMsg(61802)
End Get
End Property
Public ReadOnly Property Min_Msg As String
Get
Return EgtMsg(61616)
End Get
End Property
Public ReadOnly Property Max_Msg As String
Get
Return EgtMsg(61617)
End Get
End Property
Public ReadOnly Property CurrentLanguage_Msg As String
Get
Return EgtMsg(6501)
End Get
End Property
Public ReadOnly Property LanguageAdvert_Msg As String
Get
Return EgtMsg(6502)
End Get
End Property
Public ReadOnly Property MMUnits_Msg As String
Get
Return EgtMsg(6540)
End Get
End Property
Public ReadOnly Property Nesting_Msg As String
Get
Return EgtMsg(61829)
End Get
End Property
Public ReadOnly Property SectionTime_Msg As String
Get
Return EgtMsg(61806)
End Get
End Property
Public ReadOnly Property PartTime_Msg As String
Get
Return EgtMsg(61807)
End Get
End Property
Public ReadOnly Property DisplayIndex_Msg As String
Get
Return EgtMsg(61842)
End Get
End Property
Public ReadOnly Property ColumnName_Msg As String
Get
Return EgtMsg(61843)
End Get
End Property
Public ReadOnly Property CanUserReorder_Msg As String
Get
Return EgtMsg(61844)
End Get
End Property
Public ReadOnly Property CanUserResize_Msg As String
Get
Return EgtMsg(61845)
End Get
End Property
Public ReadOnly Property CanUserSort_Msg As String
Get
Return EgtMsg(61846)
End Get
End Property
Public ReadOnly Property IsReadOnly_Msg As String
Get
Return EgtMsg(61847)
End Get
End Property
Public ReadOnly Property Visible_Msg As String
Get
Return EgtMsg(61848)
End Get
End Property
#End Region ' Messages
#Region "Constructor"
Sub New()
' imposto riferimento in Map
Map.SetRefConfigurationPageVM(Me)
' Leggo nome lingua corrente
Dim sLanguage As String = String.Empty
GetMainPrivateProfileString(S_GENERAL, K_MESSAGES, "", sLanguage)
' Leggo elenco lingue disponibili da file ini e imposto lingua corrente
Dim nIndex As Integer = 1
While True
Dim ReadLanguage As Language = GetMainPrivateProfileLanguage(S_LANGUAGES, K_LANGUAGE & nIndex)
If IsNothing(ReadLanguage) Then Exit While
m_LanguageList.Add(ReadLanguage)
If String.Compare(ReadLanguage.Name, sLanguage, True) = 0 Then
m_SelectedLanguage = ReadLanguage
End If
nIndex += 1
End While
' Inizializzo la lingua corrente
m_SelectedLanguage = m_LanguageList(0)
Dim sMsgName As String = String.Empty
IniFile.GetMainPrivateProfileString(S_GENERAL, K_MESSAGES, "", sMsgName)
For Each Language In m_LanguageList
If Language.Name = sMsgName Then
m_SelectedLanguage = Language
Exit For
End If
Next
' leggo SectionTime e PartTime
GetMainPrivateProfileString(S_NEST, K_SECTIONTIME, "", SectionTime)
GetMainPrivateProfileString(S_NEST, K_PARTTIME, "", PartTime)
' 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()
' carico la lista di tutti i parametri Q ciclando su ogni Process di PRCList
If Not IsNothing(QBTLParamVMList) Then
QBTLParamVMList.Clear()
End If
For Each PRCItem In PRCList
For Each QBTLParam In PRCItem.QBTLParamVMList
QBTLParamVMList.Add(QBTLParam)
Next
Next
NotifyPropertyChanged(NameOf(QBTLParamVMList))
' setto il grouping a 2 livelli (GRP e, sotto, PRC col nome completo) per la DataGrid
m_QBTLParamVMList_View = CollectionViewSource.GetDefaultView(m_QBTLParamVMList)
m_QBTLParamVMList_View.GroupDescriptions.Add(New PropertyGroupDescription(NameOf(QBTLParamVM.GroupType)))
m_QBTLParamVMList_View.GroupDescriptions.Add(New PropertyGroupDescription(NameOf(QBTLParamVM.ghDesc)))
' carico la lista delle colonne delle DataGrid in ConfigurationPage
LoadConfigDGColumns()
' setto il grouping ad 1 livello per la DataGrid
m_DGColumnsList_View = CollectionViewSource.GetDefaultView(m_DGColumnsList)
m_DGColumnsList_View.GroupDescriptions.Add(New PropertyGroupDescription(NameOf(IniDataGridColumn.VisParentDataGridName)))
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()
WriteMachParamsLua()
WriteProcessParams(PRCList.ToList())
WriteDataGridColumns()
WriteMainPrivateProfileString(S_GENERAL, K_MESSAGES, m_SelectedLanguage.Name)
WriteMainPrivateProfileString(S_SCENE, K_MMUNITS, SelMeasureUnit.ToString())
WriteMainPrivateProfileString(S_NEST, K_SECTIONTIME, DoubleToString(m_SectionTime, 5))
WriteMainPrivateProfileString(S_NEST, K_PARTTIME, DoubleToString(m_PartTime, 5))
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(EgtMsg(61859), EgtMsg(30007))
Return
End If
MachParamItem.IsModifiedReset()
End If
Next
Next
' se macchina di tipo BOTH copio il file appena scritto nella cartella Beam nella cartella Wall o viceversa
If CurrentMachine.nType = MachineType.BOTH Then
If CurrentMachine.sMachParamIniFile.Contains("\" & K_BEAM & "\") Then
File.Copy(CurrentMachine.sMachParamIniFile, CurrentMachine.sMachParamIniFile.Replace("\" & K_BEAM & "\", "\" & K_WALL & "\"), True)
Else
File.Copy(CurrentMachine.sMachParamIniFile, CurrentMachine.sMachParamIniFile.Replace("\" & K_WALL & "\", "\" & K_BEAM & "\"), True)
End If
End If
End Sub
' funzione che scrive i parametri modificati sul file LUA
Private Function WriteMachParamsLua() As Boolean
' inizio routine di scrittura
Dim NewTs3DataFileContent = New List(Of String)
Dim sMachineStr As String = String.Empty
For Each MachTableItem In ConfigMachTableList
NewTs3DataFileContent.Add("local " & MachTableItem.sName & " = {")
sMachineStr &= " " & MachTableItem.sName & "=" & MachTableItem.sName & ","
For Each MachParamItem In MachTableItem.MachParamList
NewTs3DataFileContent.Add(" " & MachParamItem.sName & "=" & MachParamItem.sValue & ",")
Next
NewTs3DataFileContent.Last().TrimEnd(",")
NewTs3DataFileContent.Add("}")
NewTs3DataFileContent.Add("")
Next
NewTs3DataFileContent.Add("local Machine = {" & sMachineStr.TrimEnd(",") & "}")
NewTs3DataFileContent.Add("return Machine")
Dim FilePath As String = CurrentMachine.sMachDir & "\" & If(CurrentMachine.nType = MachineType.BEAM, BEAM_DIR, WALL_DIR) & "\" & TS3DATA_FILE
File.WriteAllLines(FilePath, NewTs3DataFileContent, Text.Encoding.UTF8)
' se macchina di tipo BOTH copio il file appena scritto nella cartella Wall nella cartella Beam
If CurrentMachine.nType = MachineType.BOTH Then File.Copy(FilePath, CurrentMachine.sMachDir & "\" & BEAM_DIR & "\" & TS3DATA_FILE, True)
Return True
End Function
' funzione che verifica la modifica dei valori in Configurazione e ne chiede il salvataggio
Friend Sub VerifyConfigPageModification()
' Prima ciclo sui parametri Macchina
Dim bExitFor = False
For Each MachTableItem In ConfigMachTableList
For Each MachParamItem In MachTableItem.MachParamList
If MachParamItem.IsModified Then
If MessageBox.Show(EgtMsg(61860), "", MessageBoxButton.YesNo, MessageBoxImage.Question) = MessageBoxResult.Yes Then
' scrivo i parametri Macchina
WriteMachParams()
WriteMachParamsLua()
Else
' se da non salvare li resetto ed esco dai For
CreateMachParams()
bExitFor = True
Exit For
End If
End If
Next
If bExitFor Then Exit For
Next
' Ora ciclo sui parametri Q
Dim bAskToSaveDefaultValues As Boolean = False
bExitFor = False
For Each PRCItem In PRCList
For Each QParam In PRCItem.QBTLParamVMList
If QParam.bIsModified Then
bAskToSaveDefaultValues = True
' esco dai For
bExitFor = True
Exit For
End If
Next
If bExitFor Then Exit For
Next
' se nel ciclo è stato trovato almeno un valore modificato chiedo il salvataggio
If bAskToSaveDefaultValues Then
If MessageBox.Show(EgtMsg(61861), "", MessageBoxButton.YesNo, MessageBoxImage.Question) = MessageBoxResult.Yes Then
' se si è scelto di salvare i valori li scrivo
WriteProcessParams(PRCList.ToList())
End If
' in ogni caso ricarico i valori (in modo da resettare i flag di modifica)
GetQParamsList()
' carico la lista di tutti i parametri Q ciclando su ogni Process di PRCList
If Not IsNothing(QBTLParamVMList) Then
QBTLParamVMList.Clear()
End If
For Each PRCItem In PRCList
For Each QBTLParam In PRCItem.QBTLParamVMList
QBTLParamVMList.Add(QBTLParam)
Next
Next
NotifyPropertyChanged(NameOf(QBTLParamVMList))
End If
' verifico se i valori delle colonne DataGrid sono stati modificati
For Each DGColumnItem In DGColumnsList
If DGColumnItem.IsModified Then
If MessageBox.Show(EgtMsg(61882), "", MessageBoxButton.YesNo, MessageBoxImage.Question) = MessageBoxResult.Yes Then
' scrivo i valori delle colonne DataGrid modificate
WriteDataGridColumns()
Else
' se da non salvare li resetto ed esco dai For
LoadConfigDGColumns()
Exit For
End If
End If
Next
End Sub
' 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 InputPwdWndVM As New InputPwdWndVM()
Dim InputPwdWnd As New InputPwdWndV(Application.Current.MainWindow, InputPwdWndVM)
If InputPwdWnd.ShowDialog() Then
' Lettura PWD dall'INI e confronto
Dim sPwdIni As String = String.Empty
If GetMainPrivateProfileString(S_MACH, K_PASSWORD, "", sPwdIni) <> 0 Then
If sPwdIni = InputPwdWndVM.sPassword Then Return True
End If
End If
Return False
End Function
Public Sub GetQParamsList()
m_PRCList.Clear()
' carico lista process
Dim TempPRCList As New ObservableCollection(Of Integer)
' prima cerco i process L (GRPType = 0)
Dim GRPType As Integer = 0
GetBeamPrivateProfileProcessList(GRPType, TempPRCList)
For Each PRC In TempPRCList
' leggo gruppi
Dim GRPList As New ObservableCollection(Of Integer)
GetBeamPrivateProfileGRPList(GRPType, PRC, GRPList)
m_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)
GRPType = 1
GetBeamPrivateProfileProcessList(GRPType, TempPRCList)
For Each PRC In TempPRCList
' leggo gruppi
Dim GRPList As New ObservableCollection(Of Integer)
GetBeamPrivateProfileGRPList(GRPType, PRC, GRPList)
m_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 QBTLParamVM)
Dim NewBTLParam As BTLParamM = Nothing
' leggo tutti i parametri P o Q del Process
ParamIndex = 1
TempList = New List(Of QBTLParamVM)
If IsP Then
While BTLIniFile.GetBeamPrivateProfileParam(GRPType, PRC, IsP, ParamIndex, Nothing, NewBTLParam)
TempList.Add(New QBTLParamVM(NewBTLParam, GRPType, PRC))
ParamIndex += 1
End While
Else
If CurrentMachine.nType = MachineType.BOTH Then
' se macchina di tipo BOTH carico i Q di tipo BEAM e poi di tipo WALL
While BTLIniFile.GetBeamPrivateProfileParam(GRPType, PRC, IsP, ParamIndex, Nothing, NewBTLParam, MachineType.BEAM)
TempList.Add(New QBTLParamVM(NewBTLParam, GRPType, PRC))
ParamIndex += 1
End While
ParamIndex = 1
While BTLIniFile.GetBeamPrivateProfileParam(GRPType, PRC, IsP, ParamIndex, Nothing, NewBTLParam, MachineType.WALL)
TempList.Add(New QBTLParamVM(NewBTLParam, GRPType, PRC))
ParamIndex += 1
End While
Else
' altrimenti carico solo quelli corrispondenti al tipo della macchina selezionata
While BTLIniFile.GetBeamPrivateProfileParam(GRPType, PRC, IsP, ParamIndex, Nothing, NewBTLParam, CurrentMachine.nType)
TempList.Add(New QBTLParamVM(NewBTLParam, GRPType, PRC))
ParamIndex += 1
End While
End If
End If
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
Dim sPrevType As String = String.Empty
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
If sPrevType <> PRCParam.sBWType Then nPRCParamIndex = 1
Dim sPRCParam As String = sType & "," & If(PRCParam.bIsP, "P", "Q") & PRCParam.nId.ToString("D2") & "," & PRCParam.sMin & "," & PRCParam.sMax & "," & PRCParam.sDefault & "," & PRCParam.sDescription
WritePrivateProfileString(CalcBeamPrivateProfileGRP(PRCItem.nGRP) & "." & PRCItem.nPRC, If(PRCParam.bIsP, "P", "Q" & PRCParam.sBWType) & nPRCParamIndex, sPRCParam, m_sBTLIniFile)
' resetto il flag per il valore modificato
PRCParam.bIsModified = False
End If
sPrevType = PRCParam.sBWType
nPRCParamIndex += 1
Next
Next
End Sub
' funzione che carica la DataGrid di configurazione delle colonne delle EgtDataGrid
Public Sub LoadConfigDGColumns()
DGColumnsList.Clear()
GetPrivateProfileIniColumns(S_FEATURELIST, DGColumnsList)
GetPrivateProfileIniColumns(S_OPENPROJFILEDLG_PROJ, DGColumnsList)
GetPrivateProfileIniColumns(S_OPENPROJFILEDLG_PROD, DGColumnsList)
GetPrivateProfileIniColumns(S_RAWPARTLIST_BEAM, DGColumnsList)
GetPrivateProfileIniColumns(S_RAWPARTLIST_WALL, DGColumnsList)
GetPrivateProfileIniColumns(S_PARTINRAWPARTLIST_BEAM, DGColumnsList)
GetPrivateProfileIniColumns(S_PARTINRAWPARTLIST_WALL, DGColumnsList)
GetPrivateProfileIniColumns(S_PARTLIST, DGColumnsList)
GetPrivateProfileIniColumns(S_FEATUREINPARTINRAWPARTLIST, DGColumnsList)
GetPrivateProfileIniColumns(S_STATISTICS, DGColumnsList)
GetPrivateProfileIniColumns(S_OPTIMIZERSTATISTICS, DGColumnsList)
GetPrivateProfileIniColumns(S_BEAMMACHININGS, DGColumnsList)
GetPrivateProfileIniColumns(S_PARAMETERLIST_P, DGColumnsList)
GetPrivateProfileIniColumns(S_PARAMETERLIST_Q, DGColumnsList)
GetPrivateProfileIniColumns(S_SPARAMLIST_BEAM, DGColumnsList)
GetPrivateProfileIniColumns(S_SPARAMLIST_WALL, DGColumnsList)
GetPrivateProfileIniColumns(S_SECTXMATLIST_BEAM, DGColumnsList)
GetPrivateProfileIniColumns(S_SECTXMATLIST_WALL, DGColumnsList)
End Sub
' funzione per calcolare e scrivere la stringhe dei parametri delle colonne relative ad una ParentDataGridName nell'INI
Public Sub SaveDataGridColumns(ParentDataGridName As String, DGColumnsList As ObservableCollection(Of IniDataGridColumn))
For Each ColumnItem In DGColumnsList
If ColumnItem.ParentDataGridName = ParentDataGridName Then
Dim sColumnParams = String.Empty
sColumnParams = ColumnItem.Name & "," & If(ColumnItem.CanUserReorder, 1, 0) & "," & If(ColumnItem.CanUserResize, 1, 0) & "," &
If(ColumnItem.CanUserSort, 1, 0) & "," & If(ColumnItem.IsReadOnly, 1, 0) & "," & DoubleToString(ColumnItem.Width.Value, 6) & "," &
ColumnItem.Width.UnitType & "," & If(ColumnItem.Visible, 1, 0) & "," & If(ColumnItem.CanUserEditVisible, 1, 0)
WriteColumnPrivateProfileParam(ParentDataGridName, ColumnItem.m_DisplayIndex, sColumnParams)
End If
Next
End Sub
' funzione che scrive i valori delle proprietà delle colonne customizzate delle EgtDataGrid nell'INI
Public Sub WriteDataGridColumns()
SaveDataGridColumns(S_FEATURELIST, DGColumnsList)
SaveDataGridColumns(S_OPENPROJFILEDLG_PROJ, DGColumnsList)
SaveDataGridColumns(S_OPENPROJFILEDLG_PROD, DGColumnsList)
SaveDataGridColumns(S_RAWPARTLIST_BEAM, DGColumnsList)
SaveDataGridColumns(S_RAWPARTLIST_WALL, DGColumnsList)
SaveDataGridColumns(S_PARTINRAWPARTLIST_BEAM, DGColumnsList)
SaveDataGridColumns(S_PARTINRAWPARTLIST_WALL, DGColumnsList)
SaveDataGridColumns(S_PARTLIST, DGColumnsList)
SaveDataGridColumns(S_FEATUREINPARTINRAWPARTLIST, DGColumnsList)
SaveDataGridColumns(S_STATISTICS, DGColumnsList)
SaveDataGridColumns(S_OPTIMIZERSTATISTICS, DGColumnsList)
SaveDataGridColumns(S_BEAMMACHININGS, DGColumnsList)
SaveDataGridColumns(S_PARAMETERLIST_P, DGColumnsList)
SaveDataGridColumns(S_PARAMETERLIST_Q, DGColumnsList)
SaveDataGridColumns(S_SPARAMLIST_BEAM, DGColumnsList)
SaveDataGridColumns(S_SPARAMLIST_WALL, DGColumnsList)
SaveDataGridColumns(S_SECTXMATLIST_BEAM, DGColumnsList)
SaveDataGridColumns(S_SECTXMATLIST_WALL, DGColumnsList)
For Each DGColumnItem In DGColumnsList
DGColumnItem.IsModifiedReset()
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
m_sDescription = MsgToString(sDescription)
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
Public Class IniDataGridColumn
Private Property m_ParentDataGridName As String
Public Property ParentDataGridName As String
Get
Return m_ParentDataGridName
End Get
Set(value As String)
m_ParentDataGridName = value
End Set
End Property
' Nome datagrid di cui fa parte la colonna visualizzato nell'interfaccia
Public ReadOnly Property VisParentDataGridName As String
Get
Return ParentDataGridName.Replace(ParentDataGridName.Substring(0, 3), "").Trim()
End Get
End Property
Private Property m_Name As String
Public Property Name As String
Get
Return m_Name
End Get
Set(value As String)
m_Name = value
End Set
End Property
' Nome colonna visualizzato nell'interfaccia
Public ReadOnly Property VisName As String
Get
Return Name.Replace(Name.Substring(0, 3), "").Trim()
End Get
End Property
Private Property m_Width As DataGridLength
Public Property Width As DataGridLength
Get
Return m_Width
End Get
Set(value As DataGridLength)
m_Width = value
End Set
End Property
Private m_IsModifiedDisplayIndex
Friend Property m_DisplayIndex As Integer
Public Property DisplayIndex As Integer
Get
Return If(Visible, m_DisplayIndex, -1)
End Get
Set(value As Integer)
m_DisplayIndex = value
m_IsModifiedDisplayIndex = (m_Name <>
GetPrivateProfileIniColumnProperty(ParentDataGridName, Map.refConfigurationPageVM.DGColumnsList, m_DisplayIndex, EgtDGColumnProperty.NAME))
' se DisplayIndex viene settato ad un valore che corrisponde a quello che aveva inizialmente aggiorno gli IsModified
' delle altre proprietà utilizzando il DisplayIndex attuale
If Not m_IsModifiedDisplayIndex Then
m_IsModifiedIsReadOnly = (m_IsReadOnly <>
GetPrivateProfileIniColumnProperty(ParentDataGridName, Map.refConfigurationPageVM.DGColumnsList, m_DisplayIndex, EgtDGColumnProperty.ISREADONLY))
m_IsModifiedCanUserReorder = (m_CanUserReorder <>
GetPrivateProfileIniColumnProperty(ParentDataGridName, Map.refConfigurationPageVM.DGColumnsList, m_DisplayIndex, EgtDGColumnProperty.REORDER))
m_IsModifiedCanUserResize = (m_CanUserResize <>
GetPrivateProfileIniColumnProperty(ParentDataGridName, Map.refConfigurationPageVM.DGColumnsList, m_DisplayIndex, EgtDGColumnProperty.RESIZE))
m_IsModifiedCanUserSort = (m_CanUserSort <>
GetPrivateProfileIniColumnProperty(ParentDataGridName, Map.refConfigurationPageVM.DGColumnsList, m_DisplayIndex, EgtDGColumnProperty.SORT))
m_IsModifiedVisible = (m_Visible <>
GetPrivateProfileIniColumnProperty(ParentDataGridName, Map.refConfigurationPageVM.DGColumnsList, m_DisplayIndex, EgtDGColumnProperty.VISIBLE))
End If
End Set
End Property
Private m_IsModifiedIsReadOnly As Boolean = False
Private Property m_IsReadOnly As Boolean = True
Public Property IsReadOnly As Boolean
Get
Return m_IsReadOnly
End Get
Set(value As Boolean)
m_IsReadOnly = value
m_IsModifiedIsReadOnly = (m_IsReadOnly <>
GetPrivateProfileIniColumnProperty(ParentDataGridName, Map.refConfigurationPageVM.DGColumnsList, m_DisplayIndex, EgtDGColumnProperty.ISREADONLY))
End Set
End Property
Private m_IsModifiedCanUserReorder As Boolean = False
Private m_CanUserReorder As Boolean
Public Property CanUserReorder As Boolean
Get
Return m_CanUserReorder
End Get
Set(value As Boolean)
m_CanUserReorder = value
m_IsModifiedCanUserReorder = (m_CanUserReorder <>
GetPrivateProfileIniColumnProperty(ParentDataGridName, Map.refConfigurationPageVM.DGColumnsList, m_DisplayIndex, EgtDGColumnProperty.REORDER))
End Set
End Property
Private m_IsModifiedCanUserResize As Boolean = False
Private m_CanUserResize As Boolean
Public Property CanUserResize As Boolean
Get
Return m_CanUserResize
End Get
Set(value As Boolean)
m_CanUserResize = value
m_IsModifiedCanUserResize = (m_CanUserResize <>
GetPrivateProfileIniColumnProperty(ParentDataGridName, Map.refConfigurationPageVM.DGColumnsList, m_DisplayIndex, EgtDGColumnProperty.RESIZE))
End Set
End Property
Private m_IsModifiedCanUserSort As Boolean = False
Private m_CanUserSort As Boolean
Public Property CanUserSort As Boolean
Get
Return m_CanUserSort
End Get
Set(value As Boolean)
m_CanUserSort = value
m_IsModifiedCanUserSort = (m_CanUserSort <>
GetPrivateProfileIniColumnProperty(ParentDataGridName, Map.refConfigurationPageVM.DGColumnsList, m_DisplayIndex, EgtDGColumnProperty.SORT))
End Set
End Property
Private m_IsModifiedVisible As Boolean = False
Private m_Visible As Boolean
Public Property Visible As Boolean
Get
Return m_Visible
End Get
Set(value As Boolean)
m_Visible = value
' Utilizzo OldDGIndex e NewDGIndex per muovere la Column tra il gruppo dei Visible (in alto) o il gruppo
' dei non Visible (in basso): in ambo i casi verrà sempre spostata in mezzo ai due raggruppamenti
Dim OldDGIndex As Integer = Map.refConfigurationPageVM.DGColumnsList.IndexOf(Me)
If value Then
Dim NewDGIndex As Integer = Map.refConfigurationPageVM.DGColumnsList.IndexOf(Map.refConfigurationPageVM.DGColumnsList.FirstOrDefault(
Function(x) x.ParentDataGridName = ParentDataGridName AndAlso
x.Visible = False))
' se NewDGIndex = -1 (ovvero ho settato l'ultima Column rimasta non Visible a Visible) oppure
' se il nuovo indice è subito dopo il vecchio non la sposto altrimenti viene spostata in maniera sbagliata
If NewDGIndex <> -1 AndAlso NewDGIndex <> OldDGIndex + 1 Then Map.refConfigurationPageVM.DGColumnsList.Move(OldDGIndex, NewDGIndex)
Else
Dim NewDGIndex As Integer = Map.refConfigurationPageVM.DGColumnsList.IndexOf(Map.refConfigurationPageVM.DGColumnsList.FirstOrDefault(
Function(x) x.ParentDataGridName = ParentDataGridName AndAlso
x.Visible = False AndAlso
x.Name <> Name))
' se NewDGIndex = -1 vuol dire che erano tutte settate a Visible perciò devo calcolare l'indice
' dell'ultima Column con quel ParentDataGridName e spostarlo lì
If NewDGIndex = -1 Then
Dim FirstIndex As Integer = Map.refConfigurationPageVM.DGColumnsList.IndexOf(Map.refConfigurationPageVM.DGColumnsList.FirstOrDefault(
Function(x) x.ParentDataGridName = ParentDataGridName))
Dim LastIndex = FirstIndex
While LastIndex < Map.refConfigurationPageVM.DGColumnsList.Count AndAlso Map.refConfigurationPageVM.DGColumnsList(LastIndex).ParentDataGridName = ParentDataGridName
LastIndex += 1
End While
NewDGIndex = LastIndex
End If
Map.refConfigurationPageVM.DGColumnsList.Move(OldDGIndex, NewDGIndex - 1)
End If
' aggiorno i DisplayIndex di ciascuna Column della ParentDataGridName in questione
Dim index = 0
For Each DGColumnItem In Map.refConfigurationPageVM.DGColumnsList
If DGColumnItem.ParentDataGridName = ParentDataGridName Then
DGColumnItem.DisplayIndex = index
index += 1
End If
Next
' uso il Move col medesimo valore per i 2 argomenti per refreshare i DisplayIndex delle Column
' della ParentDataGridName in questione appena riordinate
For index = 0 To Map.refConfigurationPageVM.DGColumnsList.Count - 1
If Map.refConfigurationPageVM.DGColumnsList(index).ParentDataGridName = ParentDataGridName Then
Map.refConfigurationPageVM.DGColumnsList.Move(index, index)
End If
Next
' setto se il valore è stato modificato, a partire dalla verifica che il Nome e DisplayIndex combacino (altrimenti è per forza modificato)
m_IsModifiedVisible = (m_Name <>
GetPrivateProfileIniColumnProperty(ParentDataGridName, Map.refConfigurationPageVM.DGColumnsList, m_DisplayIndex, EgtDGColumnProperty.NAME)) OrElse
(If(m_Visible, 1, 0) <>
GetPrivateProfileIniColumnProperty(ParentDataGridName, Map.refConfigurationPageVM.DGColumnsList, m_DisplayIndex, EgtDGColumnProperty.VISIBLE))
End Set
End Property
Private m_CanUserEditVisible As Boolean
Public Property CanUserEditVisible As Boolean
Get
Return m_CanUserEditVisible
End Get
Set(value As Boolean)
m_CanUserEditVisible = value
End Set
End Property
Public ReadOnly Property IsModified() As Boolean
Get
Return m_IsModifiedDisplayIndex OrElse
m_IsModifiedIsReadOnly OrElse
m_IsModifiedCanUserReorder OrElse
m_IsModifiedCanUserResize OrElse
m_IsModifiedCanUserSort OrElse
m_IsModifiedVisible
End Get
End Property
Public Sub IsModifiedReset()
m_IsModifiedDisplayIndex = False
m_IsModifiedIsReadOnly = False
m_IsModifiedCanUserReorder = False
m_IsModifiedCanUserResize = False
m_IsModifiedCanUserSort = False
m_IsModifiedVisible = False
End Sub
Sub New(sName As String)
m_Name = sName
End Sub
Sub New(sParentDG As String, nDisplayIndex As Integer, sName As String, bCanUserReorder As Boolean, bCanUserResize As Boolean, bCanUserSort As Boolean, bIsReadOnly As Boolean, Width As DataGridLength, bVisible As Boolean, bCanUserEditVisible As Boolean)
m_ParentDataGridName = sParentDG
m_DisplayIndex = nDisplayIndex
m_Name = sName
m_CanUserReorder = bCanUserReorder
m_CanUserResize = bCanUserResize
m_CanUserSort = bCanUserSort
m_IsReadOnly = bIsReadOnly
m_Width = Width
m_Visible = bVisible
m_CanUserEditVisible = bCanUserEditVisible
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
Public Module IniDataGridColumnFunctions
' funzione per ottenere dal file INI le colonne da caricare nella DataGrid usata per customizzare le proprietà delle colonne delle EgtDataGrid del programma
Public Function GetPrivateProfileIniColumns(ParentDGName As String, ByRef ocColumns As ObservableCollection(Of IniDataGridColumn)) As Boolean
Dim colIndex As Integer = 0
Dim str = String.Empty
While EgtUILib.GetPrivateProfileString(ParentDGName, colIndex, String.Empty, str, m_sDataGridColumnsIniFile) > 0
Dim sColumnParams() As String = str.Split(","c)
' verifico numero minimo di parametri
If sColumnParams.Count >= 9 Then
' cancello spazi
For index = 0 To sColumnParams.Count - 1
sColumnParams(index) = sColumnParams(index).Trim()
Next
' creo colonna
Dim sName = sColumnParams(0)
Dim bReorder As Boolean = sColumnParams(1).Equals("1")
Dim bResize As Boolean = sColumnParams(2).Equals("1")
Dim bSort As Boolean = sColumnParams(3).Equals("1")
Dim bIsReadOnly As Boolean = sColumnParams(4).Equals("1")
Dim Width As Double
Dim WidthType As DataGridLengthUnitType
StringToDouble(sColumnParams(5), Width)
Integer.TryParse(sColumnParams(6), WidthType)
Dim bVisible As Boolean = sColumnParams(7).Equals("1")
Dim bCanUserEditVisible As Boolean = sColumnParams(8).Equals("1")
ocColumns.Add(New IniDataGridColumn(ParentDGName, colIndex, sName, bReorder, bResize, bSort, bIsReadOnly, New DataGridLength(Width, WidthType), bVisible, bCanUserEditVisible))
End If
colIndex += 1
End While
Return ocColumns.Count > 0
End Function
' funzione che ottiene dal file INI la singola proprietà legata ad una specifica colonna
Public Function GetPrivateProfileIniColumnProperty(ParentDGName As String, ocColumns As ObservableCollection(Of IniDataGridColumn), DisplayIndex As Integer, PropertyIndex As EgtDGColumnProperty) As String
Dim str = String.Empty
If EgtUILib.GetPrivateProfileString(ParentDGName, DisplayIndex, String.Empty, str, m_sDataGridColumnsIniFile) > 0 Then
Dim sColumnParams() As String = str.Split(","c)
' verifico numero minimo di parametri
If sColumnParams.Count >= 9 Then
' cancello spazi
For index = 0 To sColumnParams.Count - 1
sColumnParams(index) = sColumnParams(index).Trim()
Next
If PropertyIndex > -1 AndAlso PropertyIndex < sColumnParams.Count Then Return sColumnParams(PropertyIndex)
End If
End If
Return ""
End Function
Public Enum EgtDGColumnProperty
NAME = 0
REORDER = 1
RESIZE = 2
SORT = 3
ISREADONLY = 4
WIDTH = 5
WIDTHTYPE = 6
VISIBLE = 7
EDITVISIBLE = 8
End Enum
End Module