From ed3e14229fa1fde2a2018a1b79428685daf7c54e Mon Sep 17 00:00:00 2001 From: RenzoL Date: Mon, 20 Dec 2021 14:54:33 +0100 Subject: [PATCH] - Nuova gestione e lettura/scrittura CurrMaterial per Db WaterJet - Modificato LoadWJMaterial --- Machine/CurrentMachine.vb | 110 ++++++++++++++++----------------- RawPhoto/RawPartPageUC.xaml.vb | 26 ++++---- 2 files changed, 67 insertions(+), 69 deletions(-) diff --git a/Machine/CurrentMachine.vb b/Machine/CurrentMachine.vb index 2d9034c..8476f8d 100644 --- a/Machine/CurrentMachine.vb +++ b/Machine/CurrentMachine.vb @@ -1006,7 +1006,11 @@ Public Class CurrentMachine End Get Set(value As Material) Dim CurrMatId As String = If(Not IsNothing(value), value.nId.ToString, "") - WritePrivateProfileString(S_MATERIALS, K_CURRMATERIAL, CurrMatId, sMachIniFile) + If bWaterJet Then + WritePrivateProfileString(S_MATERIALS, K_CURRMATERIAL, CurrMatId & If(Not IsNothing(value), "." & value.SubId, ""), sMachIniFile) + Else + WritePrivateProfileString(S_MATERIALS, K_CURRMATERIAL, CurrMatId, sMachIniFile) + End If m_CurrMat = value End Set End Property @@ -1244,7 +1248,7 @@ Public Class CurrentMachine Dim nIndex As Integer = 1 If m_bWaterJetting Then - LoadWJMaterial(nIndex) + LoadWJMaterial(True) Else While (GetPrivateProfileMaterial(S_MATERIALS, K_MATERIAL & nIndex, Material, sMachIniFile)) m_Materials.Add(Material) @@ -1256,70 +1260,47 @@ Public Class CurrentMachine m_MaxIdMat = nIndex - 1 ' Leggo materiale correntemente attivo - Dim CurrMatId As Integer = GetPrivateProfileInt(S_MATERIALS, K_CURRMATERIAL, 0, sMachIniFile) - For Each Material In Materials - If Material.nId = CurrMatId Then - m_CurrMat = Material - Exit For + Dim sCurrMatId As String = String.Empty + EgtUILib.GetPrivateProfileString(S_MATERIALS, K_CURRMATERIAL, "0", sCurrMatId, sMachIniFile) + If bWaterJet Then + Dim sCurrMatIds As String() + sCurrMatIds = sCurrMatId.Split("."c) + If sCurrMatIds.Length > 1 Then + Dim nCurrMatId As Integer + Dim nCurrSubMatId As Integer + If Not Integer.TryParse(sCurrMatIds(0), nCurrMatId) Then nCurrMatId = 0 + If Not Integer.TryParse(sCurrMatIds(1), nCurrSubMatId) Then nCurrSubMatId = 0 + For Each Material In Materials + If Material.nId = nCurrMatId AndAlso Material.SubId = nCurrSubMatId Then + m_CurrMat = Material + Exit For + End If + Next End If - Next + Else + Dim nCurrMatId As Integer + If Not Integer.TryParse(sCurrMatId, nCurrMatId) Then nCurrMatId = 0 + For Each Material In Materials + If Material.nId = nCurrMatId Then + m_CurrMat = Material + Exit For + End If + Next + End If ' leggo se la macchina ha il tastatore dello spessore tavola m_HasRawProbe = (GetPrivateProfileInt(S_MACH_PROBING, K_ENABLERAWPROBE, 1, sMachIniFile) <> 0) ' leggo se la macchina ha il lettore di codice a barre della lastra m_nEnableBarCodeReader = GetPrivateProfileInt(S_MACH_BARCODEREADER, K_ENABLEBCR, 0, sMachIniFile) End Sub - Public Sub LoadWJMaterial(ByRef nIndex As Integer) + Public Sub LoadWJMaterial(Optional bIsStart As Boolean = False) + Dim TempCurrMat As Material = CurrMat ' Svuoto l'attuale lista di materiali m_Materials.Clear() ' Leggo valori da file INI e li carico nelle proprietà Dim sFilePath As String = sMachDir & "\" & "WaterjetDb" & ".ini" Dim Local_MaterialList = New ObservableCollection(Of EgtWPFLib5.WjMaterial) - If System.IO.File.Exists(sFilePath) Then - ' vettore dei materiali - Dim sMaterial As String = String.Empty - 'recupero i Materiali - If EgtUILib.GetPrivateProfileString(S_MATERIALS, "1", "", sMaterial, sFilePath) > 0 Then - Dim sMaterials() As String = sMaterial.Split(","c) - Dim ind As Integer = 0 - For ind = 0 To sMaterials.Length() - 1 - 'recupero i Sottomateriali - Dim Index As Integer = 1 - Dim sSubMat As String = String.Empty - Dim SubMatList As New ObservableCollection(Of EgtWPFLib5.WjSubMaterial) - While EgtUILib.GetPrivateProfileString(sMaterials(ind), Index.ToString(), "", sSubMat, sFilePath) > 0 - ' recupero la lista dei Q - Dim QInd As Integer = 1 - Dim sParam As String = String.Empty - Dim QParamList As New ObservableCollection(Of EgtWPFLib5.WjParam) - While EgtUILib.GetPrivateProfileString(sMaterials(ind) & "." & sSubMat, QInd.ToString(), "", sParam, sFilePath) > 0 - Dim sParams() As String = sParam.Split(","c) - If sParams.Length() >= 7 Then - Dim dThickness As Double - Dim dQ1 As Double - Dim dQ2 As Double - Dim dQ3 As Double - Dim dQ4 As Double - Dim dQ5 As Double - Dim dQExtra As Double - StringToDouble(sParams(0), dThickness) - StringToDouble(sParams(1), dQ1) - StringToDouble(sParams(2), dQ2) - StringToDouble(sParams(3), dQ3) - StringToDouble(sParams(4), dQ4) - StringToDouble(sParams(5), dQ5) - StringToDouble(sParams(6), dQExtra) - QParamList.Add(New EgtWPFLib5.WjParam(QInd, dThickness, dQ1, dQ2, dQ3, dQ4, dQ5, dQExtra)) - End If - QInd += 1 - End While - SubMatList.Add(New EgtWPFLib5.WjSubMaterial(sSubMat, QParamList)) - Index += 1 - End While - Local_MaterialList.Add(New EgtWPFLib5.WjMaterial(sMaterials(ind), SubMatList)) - Next - End If - End If + Local_MaterialList = EgtWPFLib5.WaterjetDbWindowVM.LoadWjMaterials(sFilePath) ' definisco la lista delle qualità m_Qaulities.Add("") m_Qaulities.Add("Q1") @@ -1335,10 +1316,10 @@ Public Class CurrentMachine sName = Local_MaterialList(i).Name Dim j As Integer = 0 For j = 0 To Local_MaterialList(i).SubMaterialList.Count - 1 - m_Materials.Add(New Material(nIndex, sName & "." & Local_MaterialList(i).SubMaterialList(j).Name)) - nIndex += 1 + m_Materials.Add(New Material(i + 1, sName & "." & Local_MaterialList(i).SubMaterialList(j).Name, j + 1)) Next Next + If Not bIsStart Then CurrMat = TempCurrMat End Sub Friend Function IsVacuumMovePossible() As Boolean @@ -1435,6 +1416,7 @@ Friend Class Material Private m_nId As Integer Private m_sName As String + Private m_SubId As Integer = 0 Public ReadOnly Property nId As Integer Get @@ -1451,6 +1433,15 @@ Friend Class Material End Set End Property + Public Property SubId As Integer + Get + Return m_SubId + End Get + Set(value As Integer) + m_SubId = value + End Set + End Property + Sub New(sName As String, MaterialList As ObservableCollection(Of Material)) Dim nMaxId As Integer = 0 For Each Material As Material In MaterialList @@ -1467,4 +1458,11 @@ Friend Class Material m_sName = sName End Sub + Sub New(nId As Integer, sName As String, nSubId As Integer) + m_nId = nId + m_sName = sName + m_SubId = nSubId + End Sub + End Class + diff --git a/RawPhoto/RawPartPageUC.xaml.vb b/RawPhoto/RawPartPageUC.xaml.vb index 082c06c..ecfc1b4 100644 --- a/RawPhoto/RawPartPageUC.xaml.vb +++ b/RawPhoto/RawPartPageUC.xaml.vb @@ -140,7 +140,7 @@ Public Class RawPartPageUC ' Nascondo bottone dati lastra se non attivato da file .ini m_bSlabId = (Not m_CurrentMachine.bHasRawBarCodeReader And GetPrivateProfileInt(S_RAWPART, K_SLABID, 0, m_MainWindow.GetIniFile()) <> 0) - SlabIdBtn.Visibility = If( m_bSlabId, Windows.Visibility.Visible, Windows.Visibility.Collapsed) + SlabIdBtn.Visibility = If(m_bSlabId, Windows.Visibility.Visible, Windows.Visibility.Collapsed) m_SmartMachiningPage = GetPrivateProfileInt(S_GENERAL, "SmartMachiningPage", 0, m_MainWindow.GetIniFile()) <> 0 @@ -168,7 +168,7 @@ Public Class RawPartPageUC ' aggiorno la lista dei materiali Dim Index As Integer = 1 If m_CurrentMachine.bWaterJet Then - m_CurrentMachine.LoadWJMaterial(Index) + m_CurrentMachine.LoadWJMaterial() End If m_CurrProjPage = m_MainWindow.m_CurrentProjectPageUC @@ -288,11 +288,11 @@ Public Class RawPartPageUC End If EgtZoom(ZM.ALL) End If - ' Imposto il materiale corrente nella combobox + 'Imposto il materiale corrente nella combobox 'MaterialsCmbx.SelectedItem = m_CurrentMachine.CurrMat Dim Item As Material For Each Item In MaterialsCmbx.Items - If Item.sName = m_CurrentMachine.CurrMat.sName Then + If Not IsNothing(m_CurrentMachine.CurrMat) AndAlso Item.sName = m_CurrentMachine.CurrMat.sName Then MaterialsCmbx.SelectedItem = Item End If Next @@ -1788,7 +1788,7 @@ Public Class RawPartPageUC m_MainWindow.m_CNCommunication.m_CN.n_DReadELS_handle = 0 ' Definisco flag tastatura Dim bProbingOk As Boolean = False - For I As integer = 0 To 120 + For I As Integer = 0 To 120 ' Devo rileggere la variabile ad ogni ciclo m_MainWindow.m_CNCommunication.m_CN.ReadEls_Add_Parameter(ProbingStateNameVar, 3) System.Threading.Thread.Sleep(100) @@ -1825,7 +1825,7 @@ Public Class RawPartPageUC Dim RawThicknessNameVar As String = String.Empty GetPrivateProfileString(S_MACH_PROBING, K_RAWTHICKNESS, "", RawThicknessNameVar, m_MainWindow.GetMachIniFile()) m_MainWindow.m_CNCommunication.m_CN.n_DReadELS_handle = 0 - For I As integer = 0 To 20 + For I As Integer = 0 To 20 ' Devo rileggere la variabile ad ogni ciclo m_MainWindow.m_CNCommunication.m_CN.ReadEls_Add_Parameter(RawThicknessNameVar, 3) If m_MainWindow.m_CNCommunication.m_CN.n_DReadELS_handle = 3 Then @@ -1912,10 +1912,10 @@ Public Class RawPartPageUC Dim SlabIdWindow As New SlabIdWD(m_MainWindow) ' Recupero eventuali vecchi dati della lastra If nRawId <> GDB_ID.NULL Then - Dim sBlock As String = "" : EgtGetInfo( nRawId, INFO_RAW_BLOCK, sBlock) - Dim sSlabNbr As String = "" : EgtGetInfo( nRawId, INFO_RAW_SLABNBR, sSlabNbr) - SlabIdWindow.SetBlockName( sBlock) - SlabIdWindow.SetSlabNbr( sSlabNbr) + Dim sBlock As String = "" : EgtGetInfo(nRawId, INFO_RAW_BLOCK, sBlock) + Dim sSlabNbr As String = "" : EgtGetInfo(nRawId, INFO_RAW_SLABNBR, sSlabNbr) + SlabIdWindow.SetBlockName(sBlock) + SlabIdWindow.SetSlabNbr(sSlabNbr) End If ' Visualizzo finestra richiesta dati If SlabIdWindow.ShowDialog() Then @@ -1923,10 +1923,10 @@ Public Class RawPartPageUC Dim sBlock As String = SlabIdWindow.GetBlockName() Dim sSlabNbr As String = SlabIdWindow.GetSlabNbr() ' Li assegno - Utility.SetBlockAndSlabNbr( sBlock, sSlabNbr) + Utility.SetBlockAndSlabNbr(sBlock, sSlabNbr) ' Li salvo - WritePrivateProfileString( S_RAWPART, K_BLOCKNAME, sBlock, m_MainWindow.GetIniFile()) - WritePrivateProfileString( S_RAWPART, K_SLABNBR, sSlabNbr, m_MainWindow.GetIniFile()) + WritePrivateProfileString(S_RAWPART, K_BLOCKNAME, sBlock, m_MainWindow.GetIniFile()) + WritePrivateProfileString(S_RAWPART, K_SLABNBR, sSlabNbr, m_MainWindow.GetIniFile()) ' Aggiorno visualizzazione EgtDraw() End If