- aggiunta cartella GenDDF

- creazione ddf all'importazione
- eliminare porte solo se in reset
- gestiti file ddt e ddf in nome file ddf
- gestiti nomi con sottocartelle
- aggiunto messaggio di errore nel lua che manda in reset
- modifica per debug senza mostrare porte
This commit is contained in:
Emmanuele Sassi
2024-11-25 10:47:41 +01:00
parent 5d536f3ace
commit 7b29446f39
5 changed files with 326 additions and 90 deletions
@@ -15,12 +15,16 @@ Module ConstIni
Public Const INI_FILE_NAME As String = "Effector.Plugin.DoorArreda.ini"
Public Const S_GENERAL As String = "General"
Public Const K_CAMEXEPATH As String = "CAMExePath"
Public Const K_DOORCREATOREXEPATH As String = "DoorCreatorExePath"
Public Const K_BACKUPDIR As String = "BackupDir"
Public Const K_RESOURCESDIR As String = "ResourcesDir"
Public Const K_DDFDIR As String = "DDFDir"
Public Const K_DDTDIR As String = "DDTDir"
Public Const K_GENDDFDIR As String = "GenDDFDir"
Public Const K_CSVOUTPUT As String = "CSVOutput"
Public Const S_CSV As String = "CSV"
Public Const K_DDFNAME As String = "DDFName"
Public Const K_QUANTITY As String = "Quantity"
@@ -4,6 +4,8 @@ Imports Newtonsoft.Json
Imports System.Windows.Threading
Imports System.Text.RegularExpressions
Imports System.Security.Cryptography
Imports Newtonsoft.Json.Linq
Imports Effector.Plugin.DoorArreda.Door
Public Class DoorListPageVM
Inherits VMBase
@@ -107,9 +109,9 @@ Public Class DoorListPageVM
GetPluginPrivateProfileString(S_GENERAL, "CAMExePath", "", sCamExePath)
Dim sMainLuaPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, "MainLUA", "", sMainLuaPath)
Dim sDDFDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, "DDFDir", "", sDDFDirPath)
Dim sDDFFilePath As String = sDDFDirPath & "\" & sDDFName
Dim sGenDDFDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, K_GENDDFDIR, "", sGenDDFDirPath)
Dim sDDFFilePath As String = sGenDDFDirPath & "\" & sDDFName
Return Map.refSupervisorFunction.PlgExecProcess(sCamExePath, sMainLuaPath, sDDFFilePath)
End Function
@@ -119,9 +121,9 @@ Public Class DoorListPageVM
GetPluginPrivateProfileString(S_GENERAL, "CAMExePath", "", sCamExePath)
Dim sMainLuaPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, "MainLUA", "", sMainLuaPath)
Dim sDDFDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, "DDFDir", "", sDDFDirPath)
Dim sDDFFilePath As String = sDDFDirPath & "\" & sDDFName
Dim sGenDDFDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, K_GENDDFDIR, "", sGenDDFDirPath)
Dim sDDFFilePath As String = sGenDDFDirPath & "\" & sDDFName
Return Map.refSupervisorFunction.PlgExecProcessAsync(sCamExePath, sMainLuaPath, sDDFFilePath)
End Function
@@ -134,10 +136,11 @@ Public Class DoorListPageVM
Dim TempDoorList As ObservableCollection(Of Door) = New ObservableCollection(Of Door)((From JsonDoor In JsonDoorList
Select New Door(JsonDoor)).ToList())
For Each CurrDoor In TempDoorList
If CurrDoor.nState > Door.DoorStates.VERIFIED AndAlso CurrDoor.nState < Door.DoorStates.PRODUCED Then
CurrDoor.SetState(Door.DoorStates.VERIFIED)
If CurrDoor.nState > Door.DoorStates.VERIFIED AndAlso CurrDoor.nState < Door.DoorStates.MACHINE_1_END Then
CurrDoor.SetState(Door.DoorStates.VERIFIED, False)
End If
Next
WriteBackup()
m_DoorList = TempDoorList
End Sub
@@ -226,7 +229,7 @@ Public Class DoorListPageVM
Friend Sub ResetStateAfterReset()
For Each Door In m_DoorList
If Door.nState > Door.DoorStates.VERIFIED AndAlso Door.nState < Door.DoorStates.PRODUCED Then
Door.SetState(Door.DoorStates.VERIFIED)
Door.SetState(Door.DoorStates.VERIFIED, False)
End If
Next
End Sub
@@ -299,7 +302,7 @@ Public Class DoorListPageVM
For nValueIndex = 0 To Values.Count - 1
sLine &= Values(nValueIndex) & If(nValueIndex < Values.Count, ";", "")
Next
sLineErrorList &= "Quantity not readable in line " & sLine & ". This line will be skipped"
sLineErrorList &= "Quantity not readable in line " & sLine & ". This line will be skipped" & Environment.NewLine
Continue While
End If
End If
@@ -321,17 +324,41 @@ Public Class DoorListPageVM
dThickness = 0
End If
End If
Dim sErrMessage As String = ""
Dim sGDDFDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, K_GENDDFDIR, "", sGDDFDirPath)
Dim sGenDDFFilePath As String = ""
Dim sCopyDDFFilePath As String = ""
For nQuantityIndex = 1 To nQuantity
Dim nId As Integer = NewDoorId()
Dim NewDoor As New Door(nId, nLineIndex, Values(nDDFNameIndex), Path.GetFileName(sCSVPath),
1, dWidth, dHeight, dThickness, Headers, Values)
m_DoorList.Add(NewDoor)
Dim bOk As Boolean = False
If nQuantityIndex = 1 Then
' creo file ddf
bOk = CreateGenDdfFile(nId, Values(nDDFNameIndex), dWidth, dHeight, dThickness, sErrMessage)
If bOk Then
sGenDDFFilePath = sGDDFDirPath & "\" & If(Not String.IsNullOrWhiteSpace(Path.GetDirectoryName(Values(nDDFNameIndex))), Path.GetDirectoryName(Values(nDDFNameIndex)) & "_", "") & Path.GetFileNameWithoutExtension(Values(nDDFNameIndex)) & "_" & nId & ".ddf"
sCopyDDFFilePath = sGDDFDirPath & "\" & If(Not String.IsNullOrWhiteSpace(Path.GetDirectoryName(Values(nDDFNameIndex))), Path.GetDirectoryName(Values(nDDFNameIndex)) & "_", "") & Path.GetFileNameWithoutExtension(Values(nDDFNameIndex))
End If
Else
Try
File.Copy(sGenDDFFilePath, sCopyDDFFilePath & "_" & nId & ".ddf")
bOk = True
Catch ex As Exception
End Try
End If
If bOk Then
m_DoorList.Add(NewDoor)
End If
Next
sLineErrorList &= sErrMessage
nLineIndex += 1
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
Dim sMessage As String = "Line " & ex.Message & "is not valid and will be skipped."
' egtoutlog(sMessage)
sLineErrorList &= Environment.NewLine & ex.Message
sLineErrorList &= ex.Message & Environment.NewLine
End Try
End While
If Not String.IsNullOrWhiteSpace(sLineErrorList) Then
@@ -349,20 +376,23 @@ Public Class DoorListPageVM
AddHandler m_ExecProcessManager.m_AllArgsProcessed, AddressOf ExecProcessManager_AllArgsProcessed
m_ExecProcessManager.SetMaxCamInstances(3)
End If
Dim sDDFDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, "DDFDir", "", sDDFDirPath)
Dim sDDTDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, "DDTDir", "", sDDTDirPath)
'Dim sDDFDirPath As String = ""
'GetPluginPrivateProfileString(S_GENERAL, "DDFDir", "", sDDFDirPath)
'Dim sDDTDirPath As String = ""
'GetPluginPrivateProfileString(S_GENERAL, "DDTDir", "", sDDTDirPath)
Dim sGenDDFDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, K_GENDDFDIR, "", sGenDDFDirPath)
For Each Door In m_DoorList
If Door.nState = Door.DoorStates.LOADED_FROM_CSV Then
Dim sDDTFilePath As String = sDDTDirPath & "\" & Door.sDDFName
Dim sDDFFilePath As String = sDDFDirPath & "\" & Path.GetDirectoryName(Door.sDDFName) &
Path.GetFileNameWithoutExtension(Door.sDDFName) & "_" & Door.nId & ".ddf"
Dim sWidth As String = DoubleToString(Door.dWidth, 2)
Dim sHeight As String = DoubleToString(Door.dHeight, 2)
Dim sThickness As String = DoubleToString(Door.dThickness, 2)
Dim sArgs As String = sDDTFilePath & ";" & sWidth & ";" & sHeight & ";" & sThickness & ";" & sDDFFilePath
m_ExecProcessManager.ArgumentsEnqueue(New ProcessArgs(Door.nId, sArgs))
Dim sGenDDFFilePath As String = sGenDDFDirPath & "\" & If(Not String.IsNullOrWhiteSpace(Path.GetDirectoryName(Door.sDDFName)), Path.GetDirectoryName(Door.sDDFName) & "_", "") & Path.GetFileNameWithoutExtension(Door.sDDFName) & "_" & Door.nId & ".ddf"
'Dim sDDTFilePath As String = sDDTDirPath & "\" & Door.sDDFName
'Dim sDDFFilePath As String = sDDFDirPath & "\" & Path.GetDirectoryName(Door.sDDFName) &
' Path.GetFileNameWithoutExtension(Door.sDDFName) & "_" & Door.nId & ".ddf"
'Dim sWidth As String = DoubleToString(Door.dWidth, 2)
'Dim sHeight As String = DoubleToString(Door.dHeight, 2)
'Dim sThickness As String = DoubleToString(Door.dThickness, 2)
'Dim sArgs As String = sDDTFilePath & ";" & sWidth & ";" & sHeight & ";" & sThickness & ";" & sDDFFilePath
m_ExecProcessManager.ArgumentsEnqueue(New ProcessArgs(Door.nId, sGenDDFFilePath))
End If
Next
If bStartExecProcessManager OrElse m_ExecProcessManager.ExecutionThreadStatus = ExecProcessManager.ExecutionThreadStatuses.STOPPED Then
@@ -373,6 +403,46 @@ Public Class DoorListPageVM
WriteBackup()
End Sub
Private Function CreateGenDdfFile(nId As Integer, sDDFName As String, dWidth As Double, dHeight As Double, dThickness As Double, sErrMessage As String) As Boolean
' verifico che ci sia il file ddf
Dim sDDTDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, K_DDTDIR, "", sDDTDirPath)
Dim sDDFDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, K_DDFDIR, "", sDDFDirPath)
Dim sGenDDFDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, K_GENDDFDIR, "", sGenDDFDirPath)
Dim sExtension As String = Path.GetExtension(sDDFName)
If sExtension.ToLower() = ".ddf" Then
Dim sDDFFilePath As String = sDDFDirPath & "\" & sDDFName
If Not File.Exists(sDDFFilePath) Then
sErrMessage &= "Il nome inserito non corrisponde a nessun file nella cartella dei Ddf (" & sDDFDirPath & ")" & Environment.NewLine
NotifyPropertyChanged(NameOf(sDDFName))
Return False
End If
' copio il ddf nella cartella dei ddf
Dim sGenDDFFilePath As String = sGenDDFDirPath & "\" & If(Not String.IsNullOrWhiteSpace(Path.GetDirectoryName(sDDFName)), Path.GetDirectoryName(sDDFName) & "_", "") & Path.GetFileNameWithoutExtension(sDDFName) & "_" & nId & ".ddf"
Dim bCopy As Boolean = False
Try
File.Copy(sDDFFilePath, sGenDDFFilePath, True)
bCopy = True
Catch ex As Exception
sErrMessage &= "Error: Copy file from " & sDDFFilePath & " to " & sGenDDFFilePath & " failed!"
End Try
If Not bCopy Then
Return False
End If
ElseIf sExtension.ToLower() = ".ddt" Then
' se file generato
If Not Door.CreateDdfFromDdt(nId, sDDFName, dWidth, dHeight, dThickness) Then
Return False
End If
Else
sErrMessage &= "Estensione del file non riconosciuta!"
Return False
End If
Return True
End Function
Public Sub ExecProcessManager_AllArgsProcessed()
m_ExecProcessManager.StopExecutionThread()
End Sub
@@ -458,7 +528,7 @@ Public Class DoorListPageVM
End Try
End Sub
#End Region ' SkipDoor
#End Region ' SaveCSV
#Region "SkipDoor"
@@ -495,7 +565,7 @@ Public Class DoorListPageVM
m_DoorList.Add(New Door(nId, 0, "", m_ManualAddedDoorName, 1, 0, 0, 0, {}, {}))
End Sub
#End Region ' SkipDoor
#End Region ' AddDoor
#Region "MoveUp"
@@ -552,7 +622,11 @@ Public Class DoorListPageVM
End Property
Public Sub Delete()
If IsNothing(SelDoor) OrElse (SelDoor.nState >= Door.DoorStates.READY_FOR_PRODUCTION AndAlso SelDoor.nState < Door.DoorStates.PRODUCED) Then Return
If IsNothing(SelDoor) Then Return
Dim bReset As Boolean = True
If Not LuaGetGlobVar("bReset", bReset) OrElse Not bReset Then
If (SelDoor.nState >= Door.DoorStates.READY_FOR_PRODUCTION AndAlso SelDoor.nState < Door.DoorStates.MACHINE_1_END) Then Return
End If
If MessageBox.Show("Are you sure you want to delete the selected door?", "Info", MessageBoxButton.YesNo, MessageBoxImage.Information) = MessageBoxResult.Yes Then
m_DoorList.Remove(SelDoor)
WriteBackup()
@@ -577,7 +651,7 @@ Public Class DoorListPageVM
If MessageBox.Show("Are you sure you want to delete all the doors?", "Info", MessageBoxButton.YesNo, MessageBoxImage.Information) = MessageBoxResult.Yes Then
For nDoorIndex = m_DoorList.Count - 1 To 0 Step -1
Dim Door As Door = m_DoorList(nDoorIndex)
If Door.nState >= Door.DoorStates.READY_FOR_PRODUCTION AndAlso Door.nState < Door.DoorStates.PRODUCED Then Continue For
If Door.nState >= Door.DoorStates.READY_FOR_PRODUCTION AndAlso Door.nState < Door.DoorStates.MACHINE_1_END Then Continue For
m_DoorList.Remove(Door)
Next
WriteBackup()
@@ -602,7 +676,7 @@ Public Class DoorListPageVM
WriteBackup()
End Sub
Public Sub ProduceDoor(DoorToProduce As Door)
Public Sub ProduceDoor(DoorToProduce As Door, Optional bWriteBackup As Boolean = True)
If IsNothing(DoorToProduce) OrElse DoorToProduce.nState = Door.DoorStates.SKIPPED OrElse
DoorToProduce.nState = Door.DoorStates.VERIFICATION_FAILED OrElse
DoorToProduce.nState >= Door.DoorStates.READY_FOR_PRODUCTION Then Return
@@ -610,7 +684,7 @@ Public Class DoorListPageVM
Dim nNewIndex As Integer = m_DoorList.IndexOf(m_DoorList.FirstOrDefault(Function(x) x.nState < Door.DoorStates.READY_FOR_PRODUCTION))
Dim nOldIndex As Integer = m_DoorList.IndexOf(DoorToProduce)
m_DoorList.Move(nOldIndex, nNewIndex)
DoorToProduce.SetState(Door.DoorStates.READY_FOR_PRODUCTION)
DoorToProduce.SetState(Door.DoorStates.READY_FOR_PRODUCTION, bWriteBackup)
End Sub
#End Region ' Produce
@@ -630,7 +704,7 @@ Public Class DoorListPageVM
If m_DoorList.Count = 0 Then Return
For nDoorIndex = 0 To m_DoorList.Count - 1
Dim CurrDoor As Door = m_DoorList(nDoorIndex)
ProduceDoor(CurrDoor)
ProduceDoor(CurrDoor, False)
Next
WriteBackup()
End Sub
@@ -687,20 +761,12 @@ Public Class DoorListPageVM
AddHandler m_ExecProcessManager.m_AllArgsProcessed, AddressOf ExecProcessManager_AllArgsProcessed
m_ExecProcessManager.SetMaxCamInstances(3)
End If
Dim sDDFDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, "DDFDir", "", sDDFDirPath)
Dim sDDTDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, "DDTDir", "", sDDTDirPath)
Dim sGenDDFDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, K_GENDDFDIR, "", sGenDDFDirPath)
For Each Door In m_DoorList
If Door.nState = Door.DoorStates.LOADED_FROM_CSV Or Door.nState = Door.DoorStates.VERIFICATION_FAILED Then
Dim sDDTFilePath As String = sDDTDirPath & "\" & Door.sDDFName
Dim sDDFFilePath As String = sDDFDirPath & "\" & Path.GetDirectoryName(Door.sDDFName) &
Path.GetFileNameWithoutExtension(Door.sDDFName) & "_" & Door.nId & ".ddf"
Dim sWidth As String = DoubleToString(Door.dWidth, 2)
Dim sHeight As String = DoubleToString(Door.dHeight, 2)
Dim sThickness As String = DoubleToString(Door.dThickness, 2)
Dim sArgs As String = sDDTFilePath & ";" & sWidth & ";" & sHeight & ";" & sThickness & ";" & sDDFFilePath
m_ExecProcessManager.ArgumentsEnqueue(New ProcessArgs(Door.nId, sArgs))
Dim sGenDDFFilePath As String = sGenDDFDirPath & "\" & If(Not String.IsNullOrWhiteSpace(Path.GetDirectoryName(Door.sDDFName)), Path.GetDirectoryName(Door.sDDFName) & "_", "") & Path.GetFileNameWithoutExtension(Door.sDDFName) & "_" & Door.nId & ".ddf"
m_ExecProcessManager.ArgumentsEnqueue(New ProcessArgs(Door.nId, sGenDDFFilePath))
End If
Next
If bStartExecProcessManager OrElse m_ExecProcessManager.ExecutionThreadStatus = ExecProcessManager.ExecutionThreadStatuses.STOPPED Then
@@ -719,6 +785,8 @@ End Class
Public Class Door
Inherits VMBase
Private Shared m_refWriteBackup As Action
Public Enum DoorStates As Integer
NULL = 0
LOADED_FROM_CSV = 1
@@ -769,32 +837,52 @@ Public Class Door
Set(value As String)
' verifico che ci sia il file ddf
Dim sDDTDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, "DDTDir", "", sDDTDirPath)
If Not File.Exists(sDDTDirPath & "\" & value) Then
MessageBox.Show("Il nome inserito non corrisponde a nessun file nella cartella dei Ddt (" & sDDTDirPath & ") ", "File non trovato!", MessageBoxButton.OK, MessageBoxImage.Error)
NotifyPropertyChanged(NameOf(sDDFName))
Else
m_sDDFName = value
' creo il ddf
Dim Proc As New Process()
Proc.StartInfo.FileName = "c:\EgtProg\EgtDOORCreator\EgtDOORCreatorR32.exe"
Proc.StartInfo.RedirectStandardInput = False
Proc.StartInfo.RedirectStandardOutput = False
' Proc.StartInfo.Arguments = 1.ToString() & " """ & sMainLuaPath & """ """ & sArguments & """"
Proc.StartInfo.Arguments = "c:\EgtData\Effector\Ddf-DoorArreda\Ddt\Prova_Apertura_TEMPLATE.ddt;" & "800.55;1800.33;30.22" & ";c:\EgtData\Effector\Ddf-DoorArreda\Ddt\Prova_Apertura_TEMPLATE.ddf"
Proc.StartInfo.UseShellExecute = False
Proc.StartInfo.CreateNoWindow = True
Dim ExecCounter = 0
If Proc.Start Then
While Not Proc.HasExited
If ExecCounter >= 30 Then
Proc.Kill()
Exit While
End If
Threading.Thread.Sleep(100)
ExecCounter += 1
End While
GetPluginPrivateProfileString(S_GENERAL, K_DDTDIR, "", sDDTDirPath)
Dim sDDFDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, K_DDFDIR, "", sDDFDirPath)
Dim sGenDDFDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, K_GENDDFDIR, "", sGenDDFDirPath)
Dim sExtension As String = Path.GetExtension(value)
If sExtension.ToLower() = ".ddf" Then
Dim sDDFFilePath As String = sDDFDirPath & "\" & value
If Not File.Exists(sDDFFilePath) Then
MessageBox.Show("Il nome inserito non corrisponde a nessun file nella cartella dei Ddf (" & sDDFDirPath & ") ", "File non trovato!", MessageBoxButton.OK, MessageBoxImage.Error)
NotifyPropertyChanged(NameOf(sDDFName))
Return
End If
Me.m_sDDFName = value
' copio il ddf nella cartella dei ddf
Dim sGenDDFFilePath As String = sGenDDFDirPath & "\" & If(Not String.IsNullOrWhiteSpace(Path.GetDirectoryName(m_sDDFName)), Path.GetDirectoryName(m_sDDFName) & "_", "") & Path.GetFileNameWithoutExtension(m_sDDFName) & "_" & Me.nId & ".ddf"
Dim bCopy As Boolean = False
Try
File.Copy(sDDFFilePath, sGenDDFFilePath, True)
bCopy = True
Catch ex As Exception
Map.refSupervisorFunction.PlgOutLog("Error: Copy file from " & sDDFFilePath & " to " & sGenDDFFilePath & " failed!")
End Try
If bCopy Then
' riporto indietro stato a da verificare
Me.m_nState = DoorStates.LOADED_FROM_CSV
NotifyPropertyChanged(NameOf(nState))
Else
NotifyPropertyChanged(NameOf(sDDFName))
Return
End If
ElseIf sExtension.ToLower() = ".ddt" Then
' se file generato
If CreateDdfFromDdt(m_nId, value, m_dWidth, m_dHeight, m_dThickness) Then
Me.m_sDDFName = value
' riporto indietro stato a da verificare
Me.m_nState = DoorStates.LOADED_FROM_CSV
NotifyPropertyChanged(NameOf(nState))
Else
NotifyPropertyChanged(NameOf(sDDFName))
Return
End If
Else
MessageBox.Show("Estensione del file non riconosciuta!", "Errore!", MessageBoxButton.OK, MessageBoxImage.Error)
NotifyPropertyChanged(NameOf(sDDFName))
Return
End If
End Set
End Property
@@ -807,32 +895,96 @@ Public Class Door
End Property
Private m_dWidth As Double
Public Property dWidth As Double
Public Property dWidth As String
Get
Return m_dWidth
Return DoubleToString(m_dWidth, 2)
End Get
Set(value As Double)
m_dWidth = value
Set(value As String)
Dim dValue As Double = 0
If Not StringToDouble(value, dValue) Then
MessageBox.Show("Dimensione non valida!", "Errore!", MessageBoxButton.OK, MessageBoxImage.Error)
NotifyPropertyChanged(NameOf(dWidth))
Return
End If
' verifico se file ddf o ddt
Dim sExtension As String = Path.GetExtension(m_sDDFName)
If sExtension.ToLower() = ".ddf" Then
MessageBox.Show("ATTENZIONE! Questa modifica non cambia realmente le dimensioni della porta perchè è selezionato un file ddf!", "Attenzione!", MessageBoxButton.OK, MessageBoxImage.Warning)
m_dWidth = dValue
Return
ElseIf sExtension.ToLower() = ".ddt" Then
If CreateDdfFromDdt(m_nId, m_sDDFName, dValue, m_dHeight, m_dThickness) Then
m_dWidth = dValue
' riporto indietro stato a da verificare
Me.m_nState = DoorStates.LOADED_FROM_CSV
NotifyPropertyChanged(NameOf(nState))
Else
NotifyPropertyChanged(NameOf(dWidth))
Return
End If
End If
End Set
End Property
Private m_dHeight As Double
Public Property dHeight As Double
Public Property dHeight As String
Get
Return m_dHeight
Return DoubleToString(m_dHeight, 2)
End Get
Set(value As Double)
m_dHeight = value
Set(value As String)
Dim dValue As Double = 0
If Not StringToDouble(value, dValue) Then
MessageBox.Show("Dimensione non valida!", "Errore!", MessageBoxButton.OK, MessageBoxImage.Error)
NotifyPropertyChanged(NameOf(dHeight))
Return
End If
' verifico se file ddf o ddt
Dim sExtension As String = Path.GetExtension(m_sDDFName)
If sExtension.ToLower() = ".ddf" Then
m_dHeight = dValue
Return
ElseIf sExtension.ToLower() = ".ddt" Then
If CreateDdfFromDdt(m_nId, m_sDDFName, m_dWidth, dValue, m_dThickness) Then
m_dHeight = dValue
' riporto indietro stato a da verificare
Me.m_nState = DoorStates.LOADED_FROM_CSV
NotifyPropertyChanged(NameOf(nState))
Else
NotifyPropertyChanged(NameOf(dHeight))
Return
End If
End If
End Set
End Property
Private m_dThickness As Double
Public Property dThickness As Double
Public Property dThickness As String
Get
Return m_dThickness
Return DoubleToString(m_dThickness, 2)
End Get
Set(value As Double)
m_dThickness = value
Set(value As String)
Dim dValue As Double = 0
If Not StringToDouble(value, dValue) Then
MessageBox.Show("Dimensione non valida!", "Errore!", MessageBoxButton.OK, MessageBoxImage.Error)
NotifyPropertyChanged(NameOf(dThickness))
Return
End If
' verifico se file ddf o ddt
Dim sExtension As String = Path.GetExtension(m_sDDFName)
If sExtension.ToLower() = ".ddf" Then
m_dThickness = dValue
Return
ElseIf sExtension.ToLower() = ".ddt" Then
If CreateDdfFromDdt(m_nId, m_sDDFName, m_dWidth, m_dHeight, dValue) Then
m_dThickness = dValue
' riporto indietro stato a da verificare
Me.m_nState = DoorStates.LOADED_FROM_CSV
NotifyPropertyChanged(NameOf(nState))
Else
NotifyPropertyChanged(NameOf(dThickness))
Return
End If
End If
End Set
End Property
@@ -856,8 +1008,9 @@ Public Class Door
Return m_nState
End Get
End Property
Friend Sub SetState(value As DoorStates, Optional bUpdate As Boolean = True)
Friend Sub SetState(value As DoorStates, Optional bWriteBackup As Boolean = True, Optional bUpdate As Boolean = True)
m_nState = value
If bWriteBackup Then Map.refDoorListPageVM.WriteBackup()
If bUpdate Then
NotifyPropertyChanged(NameOf(nState))
NotifyPropertyChanged(NameOf(Background))
@@ -1045,6 +1198,49 @@ Public Class Door
m_dtUnloadTime = JsonDoor.dtUnloadTime
End Sub
Friend Shared Function CreateDdfFromDdt(nId As Integer, sDDFName As String, dWidth As Double, dHeight As Double, dThickness As Double) As Boolean
Dim sDoorCreatorExePath As String = ""
GetPluginPrivateProfileString(S_GENERAL, K_DOORCREATOREXEPATH, "", sDoorCreatorExePath)
Dim sDDTDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, K_DDTDIR, "", sDDTDirPath)
Dim sGenDDFDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, K_GENDDFDIR, "", sGenDDFDirPath)
Dim sDDTFilePath As String = sDDTDirPath & "\" & sDDFName
If String.IsNullOrWhiteSpace(sDoorCreatorExePath) OrElse Not File.Exists(sDoorCreatorExePath) Then
MessageBox.Show("Path del programma di calcolo del ddf mancante o errata!", "Errore!", MessageBoxButton.OK, MessageBoxImage.Error)
Return False
ElseIf Not File.Exists(sDDTFilePath) Then
MessageBox.Show("Il nome inserito non corrisponde a nessun file nella cartella dei Ddt (" & sDDTDirPath & ") ", "File non trovato!", MessageBoxButton.OK, MessageBoxImage.Error)
Return False
End If
' creo il ddf
Dim sGenDDFFilePath As String = sGenDDFDirPath & "\" & If(Not String.IsNullOrWhiteSpace(Path.GetDirectoryName(sDDFName)), Path.GetDirectoryName(sDDFName) & "_", "") & Path.GetFileNameWithoutExtension(sDDFName) & "_" & nId & ".ddf"
Dim Proc As New Process()
Proc.StartInfo.FileName = """" & sDoorCreatorExePath & """"
Proc.StartInfo.RedirectStandardInput = False
Proc.StartInfo.RedirectStandardOutput = False
Proc.StartInfo.Arguments = """" & sDDTFilePath & ";" & DoubleToString(dWidth, 2) & ";" & DoubleToString(dHeight, 2) & ";" & DoubleToString(dThickness, 2) & ";" & sGenDDFFilePath & """"
Proc.StartInfo.UseShellExecute = False
Proc.StartInfo.CreateNoWindow = True
Dim ExecCounter = 0
If Proc.Start Then
While Not Proc.HasExited
If ExecCounter >= 30 Then
Proc.Kill()
Exit While
End If
Threading.Thread.Sleep(100)
ExecCounter += 1
End While
End If
' se file generato
If Not File.Exists(sGenDDFFilePath) Then
MessageBox.Show("Generazione file ddf fallita!", "Errore!", MessageBoxButton.OK, MessageBoxImage.Error)
Return False
End If
Return True
End Function
End Class
Public Class CustomerParameter
@@ -109,7 +109,8 @@ Public Module Lua_General
If Not IsNothing(NextDoor) Then
' restituisco il risultato
LuaSetParam(state, NextDoor.nId)
LuaSetParam(state, Path.GetFileNameWithoutExtension(NextDoor.sDDFName) & "_" & NextDoor.nId & ".ddf")
LuaSetParam(state, If(Not String.IsNullOrWhiteSpace(Path.GetDirectoryName(NextDoor.sDDFName)), Path.GetDirectoryName(NextDoor.sDDFName) & "_", "") & Path.GetFileNameWithoutExtension(NextDoor.sDDFName) & "_" & NextDoor.nId & ".ddf")
'LuaSetParam(state, Path.GetFileNameWithoutExtension(NextDoor.sDDFName) & "_" & NextDoor.nId & ".ddf")
Return 2
End If
Return 0
@@ -14,6 +14,7 @@
<local:StringToBooleanConverter x:Key="StringToBooleanConverter"/>
<local:StringToBackgroundConverter x:Key="StringToBackgroundConverter"/>
<local:DoorToVisibilityConverter x:Key="DoorToVisibilityConverter"/>
<local:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
@@ -56,6 +57,7 @@
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Column="0"
Grid.Row="0"
@@ -69,6 +71,10 @@
<TextBlock Grid.Column="2"
Grid.Row="1"
Text="{Binding nNewDoorState, Converter={StaticResource StringToNewDoorStateConverter}}"/>
<TextBlock Grid.ColumnSpan="2"
Grid.Row="2"
Text="Errore nella generazione programma!&#x0d;&#x0a;Verificare nel file di log!&#x0d;&#x0a;Chiudere il programma e riaprirlo dopo aver risolto!"
Visibility="{Binding bErrorReset, Converter={StaticResource BooleanToVisibilityConverter}}"/>
</Grid>
<Grid Grid.Row="1"
VerticalAlignment="Center">
@@ -101,7 +107,7 @@
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<TextBlock Text="{Binding VariableList[12].sValue, Converter={StaticResource StringToMachineStateConverter}}"
<TextBlock Text="{Binding VariableList[5].sValue, Converter={StaticResource StringToMachineStateConverter}}"
Style="{StaticResource MachDrawVar_TextBlock}"/>
<Button Grid.Row="1"
Content="Initialize"
@@ -76,6 +76,13 @@ Public Class MachinePageVM
End Get
End Property
Private m_bErrorReset As Boolean = False
Public ReadOnly Property bErrorReset As Boolean
Get
Return m_bErrorReset
End Get
End Property
Public ReadOnly Property VariableList_Visibility As Visibility
Get
Return If(GetPluginPrivateProfileInt(S_DEBUG, K_VARIABLELIST, 0) <> 0, Visibility.Visible, Visibility.Collapsed)
@@ -159,6 +166,9 @@ Public Class MachinePageVM
End Sub
Friend Sub VarTimer_Tick()
' leggo variabile ErrorReset da lua
LuaGetGlobVar("ERROR_RESET", m_bErrorReset)
NotifyPropertyChanged(NameOf(bErrorReset))
' leggo variabili da macchina
For nVarIndex As Integer = 0 To m_VariableList.Count - 1
Dim Var As Variable = m_VariableList(nVarIndex)
@@ -546,36 +556,41 @@ Public Class MachinePageVM
Dim StateVariable As Variable = m_VariableList.FirstOrDefault(Function(x) x.nMachine = nMachineIndex AndAlso x.sName = "@STATE")
Dim Sent1 As Variable = m_VariableList.FirstOrDefault(Function(x) x.nMachine = nMachineIndex AndAlso x.sName = "@SENT_1")
Dim Sent2 As Variable = m_VariableList.FirstOrDefault(Function(x) x.nMachine = nMachineIndex AndAlso x.sName = "@SENT_2")
Dim StartDoorPresence As Variable = m_VariableList.FirstOrDefault(Function(x) x.nMachine = nMachineIndex AndAlso x.sName = "@WP_PR_00")
Dim EndDoorPresence As Variable = m_VariableList.FirstOrDefault(Function(x) x.nMachine = nMachineIndex AndAlso x.sName = "@WP_PR_02")
Dim StartDoorPresence As Variable = m_VariableList.FirstOrDefault(Function(x) x.nMachine = nMachineIndex AndAlso x.sName = "@WP_PR_03")
Dim EndDoorPresence As Variable = m_VariableList.FirstOrDefault(Function(x) x.nMachine = nMachineIndex AndAlso x.sName = "@WP_PR_01")
If StateVariable.nValue < 1 OrElse StateVariable.nValue > 5 Then Return
Select Case StateVariable.nValue
Case 0
Return
Case 1
If nStartStop = 1 AndAlso StartDoorPresence.dValue = 1 AndAlso Sent1.nValue = 1 Then
'If nStartStop = 1 AndAlso StartDoorPresence.dValue = 1 AndAlso Sent1.nValue = 1 Then
If nStartStop = 1 AndAlso Sent1.nValue = 1 Then
nState = 2
Map.refSupervisorFunction.ComWriteShortVar(Sent1.sIndex, 0, nMachineIndex)
Else Return
End If
Case 2
If nStartStop = 2 AndAlso EndDoorPresence.dValue = 2 Then
'If nStartStop = 2 AndAlso EndDoorPresence.dValue = 2 Then
If nStartStop = 2 Then
nState = 3
Else Return
End If
Case 3
If nStartStop = 1 AndAlso StartDoorPresence.dValue = 1 AndAlso Sent2.nValue = 1 Then
'If nStartStop = 1 AndAlso StartDoorPresence.dValue = 1 AndAlso Sent2.nValue = 1 Then
If nStartStop = 1 AndAlso Sent2.nValue = 1 Then
nState = 4
Map.refSupervisorFunction.ComWriteShortVar(Sent2.sIndex, 0, nMachineIndex)
Else Return
End If
Case 4
If nStartStop = 2 AndAlso EndDoorPresence.dValue = 2 Then
'If nStartStop = 2 AndAlso EndDoorPresence.dValue = 2 Then
If nStartStop = 2 Then
nState = 5
Else Return
End If
Case 5
If nStartStop = 1 AndAlso StartDoorPresence.dValue = 1 AndAlso Sent1.nValue = 1 Then
'If nStartStop = 1 AndAlso StartDoorPresence.dValue = 1 AndAlso Sent1.nValue = 1 Then
If nStartStop = 1 AndAlso Sent1.nValue = 1 Then
nState = 2
Map.refSupervisorFunction.ComWriteShortVar(Sent1.sIndex, 0, nMachineIndex)
Else Return
@@ -974,3 +989,17 @@ Public Class DoorToVisibilityConverter
End Function
End Class
Public Class BooleanToVisibilityConverter
Implements IValueConverter
Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.Convert
If IsNothing(value) OrElse (Not TypeOf value Is Boolean) Then Return Visibility.Hidden
Return If(value, Visibility.Visible, Visibility.Hidden)
End Function
Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.ConvertBack
Throw New NotImplementedException()
End Function
End Class