ee575750da
- primo salvataggio.
307 lines
12 KiB
VB.net
307 lines
12 KiB
VB.net
Imports System.Collections.ObjectModel
|
|
Imports System.IO
|
|
Imports EgtUILib
|
|
Imports System.Text.RegularExpressions
|
|
|
|
Friend Module DdfFile
|
|
|
|
Friend m_Door As New Door
|
|
Private FileContent As String()
|
|
|
|
#Region "Lettura ddf"
|
|
|
|
Public Function ReadDDF(sPath As String) As Boolean
|
|
If Not File.Exists(sPath) Then Return False
|
|
FileContent = File.ReadAllLines(sPath)
|
|
If FileContent.Count = 0 Then Return False
|
|
For LineIndex As Integer = 0 To FileContent.Count - 1
|
|
' size
|
|
If SearchKey(FileContent(LineIndex), K_SIZE) Then
|
|
LineIndex = GetSize(LineIndex + 1)
|
|
If LineIndex = -1 Then
|
|
MessageBox.Show("Errore in lettura DDF", "Errore", MessageBoxButton.OK, MessageBoxImage.Error)
|
|
End If
|
|
End If
|
|
'' swing
|
|
'If SearchKey(FileContent(LineIndex), K_SWING) Then
|
|
' If Not GetProfiles(LineIndex + 1) Then
|
|
' MessageBox.Show("Errore in lettura DDF", "Errore", MessageBoxButton.OK, MessageBoxImage.Error)
|
|
' End If
|
|
'End If
|
|
' profiles
|
|
If SearchKey(FileContent(LineIndex), K_PROFILES) Then
|
|
LineIndex = GetProfiles(LineIndex + 1)
|
|
If LineIndex = -1 Then
|
|
MessageBox.Show("Errore in lettura DDF", "Errore", MessageBoxButton.OK, MessageBoxImage.Error)
|
|
End If
|
|
End If
|
|
Next
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function SearchKeyValue(sLine As String, sKey As String) As String
|
|
Return Regex.Match(sLine, "\s*" & sKey & "\s*:\s*(.*?\b)\s*$").Groups(1).Value
|
|
End Function
|
|
|
|
Friend Function SearchKey(sLine As String, sKey As String) As Boolean
|
|
If Not Regex.Match(sLine, "\s*(" & sKey & ")\s*:\s*$").Groups(1).Value = sKey Then Return False
|
|
Return True
|
|
End Function
|
|
|
|
|
|
'' Lettura di file DDF e scrittura su lista
|
|
'Public Function ReadDDF(ByRef DdfList As List(Of String)) As Boolean
|
|
' ' Path Compo.ini file
|
|
' Dim m_sCompoIniFile As String = String.Empty
|
|
' ' Path DdfFile
|
|
' Dim m_sDdfFile As New StreamReader("c:\EgtData\EgtDOORCreator\Myprojects\Prova1.ddf")
|
|
' Dim sLine As String = String.Empty
|
|
|
|
' ' Lettura e caricamento del file ddf su una lista
|
|
' Do
|
|
' sLine = m_sDdfFile.ReadLine()
|
|
' If Not sLine Is Nothing Then
|
|
' DdfList.Add(sLine)
|
|
' End If
|
|
' Loop Until sLine Is Nothing
|
|
' m_sDdfFile.Close()
|
|
' Return True
|
|
'End Function
|
|
|
|
' Cerco l'indice del paragrafo
|
|
Private Function DDFGetLeadIndex(ByRef DdfList As List(Of String), ByRef Lead As String) As Integer
|
|
Dim Index As Integer
|
|
For Index = 0 To DdfList.Count()
|
|
If LTrim(DdfList.Item(Index)) = DdfList.Item(Index) Then
|
|
Dim sItem() As String = DdfList.Item(Index).Split(":".ToCharArray)
|
|
If sItem(0) = Lead Then
|
|
Return Index
|
|
End If
|
|
End If
|
|
Next
|
|
Return -1
|
|
End Function
|
|
|
|
' carico valori di Size
|
|
Public Function GetSize(Index As Integer) As Integer
|
|
Dim Width As String = SearchKeyValue(FileContent(Index), K_WIDTH)
|
|
If String.IsNullOrEmpty(Width) Then
|
|
If Not SearchKey(FileContent(Index), K_LOCKEDGE) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.Width = Width
|
|
Index += 1
|
|
End If
|
|
Dim Height As String = SearchKeyValue(FileContent(Index), K_HEIGHT)
|
|
If String.IsNullOrEmpty(Height) Then
|
|
If Not SearchKey(FileContent(Index), K_HEIGHT) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.Height = Height
|
|
Index += 1
|
|
End If
|
|
Dim Thickness As String = SearchKeyValue(FileContent(Index), K_THICKNESS)
|
|
If String.IsNullOrEmpty(Thickness) Then
|
|
If Not SearchKey(FileContent(Index), K_THICKNESS) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.Thickness = Thickness
|
|
Index += 1
|
|
End If
|
|
Return Index
|
|
End Function
|
|
|
|
' carico valori swing
|
|
Public Function DDFGetSwing(ByRef DdfList As List(Of String)) As Boolean
|
|
Dim Index As Integer = DDFGetLeadIndex(DdfList, K_SWING)
|
|
If Index <> -1 Then
|
|
Dim sItem() As String = DdfList.Item(Index).Split(":".ToCharArray)
|
|
m_Door.Swing = sItem(1)
|
|
Return True
|
|
Else
|
|
Return False
|
|
End If
|
|
End Function
|
|
|
|
Public Function ConvertStringToBoolean(sItem As String) As Boolean
|
|
If sItem = K_ON Then
|
|
Return True
|
|
Else
|
|
Return False
|
|
End If
|
|
End Function
|
|
|
|
' carico valori profiles
|
|
Public Function GetProfiles(Index As Integer) As Integer
|
|
|
|
' Lock
|
|
Dim LockEdgeType As String = SearchKeyValue(FileContent(Index), K_LOCKEDGE)
|
|
If String.IsNullOrEmpty(LockEdgeType) Then
|
|
If Not SearchKey(FileContent(Index), K_LOCKEDGE) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.LockEdgeType = LockEdgeType
|
|
Index += 1
|
|
End If
|
|
Dim LockEdgeMachining As String = SearchKeyValue(FileContent(Index), K_MACHINING)
|
|
If String.IsNullOrEmpty(LockEdgeMachining) Then
|
|
If Not SearchKey(FileContent(Index), K_MACHINING) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.LockEdgeMachining = ConvertStringToBoolean(LockEdgeMachining)
|
|
Index += 1
|
|
End If
|
|
Dim LockEdgeOverMaterial As String = SearchKeyValue(FileContent(Index), K_OVERMATERAL)
|
|
If String.IsNullOrEmpty(LockEdgeOverMaterial) Then
|
|
If Not SearchKey(FileContent(Index), K_OVERMATERAL) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.LockEdgeOverMaterial = LockEdgeOverMaterial
|
|
Index += 1
|
|
End If
|
|
|
|
' Hinge
|
|
Dim HingeEdgeType As String = SearchKeyValue(FileContent(Index), K_HINGEEDGE)
|
|
If String.IsNullOrEmpty(HingeEdgeType) Then
|
|
If Not SearchKey(FileContent(Index), K_HINGEEDGE) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.HingeEdgeType = HingeEdgeType
|
|
Index += 1
|
|
End If
|
|
Dim HingeEdgeMachining As String = SearchKeyValue(FileContent(Index), K_MACHINING)
|
|
If String.IsNullOrEmpty(HingeEdgeMachining) Then
|
|
If Not SearchKey(FileContent(Index), K_MACHINING) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.HingeEdgeMachining = ConvertStringToBoolean(HingeEdgeMachining)
|
|
Index += 1
|
|
End If
|
|
Dim HingeEdgeOverMaterial As String = SearchKeyValue(FileContent(Index), K_OVERMATERAL)
|
|
If String.IsNullOrEmpty(HingeEdgeOverMaterial) Then
|
|
If Not SearchKey(FileContent(Index), K_OVERMATERAL) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.HingeEdgeOverMaterial = HingeEdgeOverMaterial
|
|
Index += 1
|
|
End If
|
|
|
|
' Top
|
|
Dim TopType As String = SearchKeyValue(FileContent(Index), K_TOP)
|
|
If String.IsNullOrEmpty(TopType) Then
|
|
If Not SearchKey(FileContent(Index), K_TOP) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.TopType = TopType
|
|
Index += 1
|
|
End If
|
|
Dim TopMachining As String = SearchKeyValue(FileContent(Index), K_MACHINING)
|
|
If String.IsNullOrEmpty(TopMachining) Then
|
|
If Not SearchKey(FileContent(Index), K_MACHINING) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.TopMachining = ConvertStringToBoolean(TopMachining)
|
|
Index += 1
|
|
End If
|
|
Dim TopOverMaterial As String = SearchKeyValue(FileContent(Index), K_OVERMATERAL)
|
|
If String.IsNullOrEmpty(TopOverMaterial) Then
|
|
If Not SearchKey(FileContent(Index), K_OVERMATERAL) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.TopOverMaterial = TopOverMaterial
|
|
Index += 1
|
|
End If
|
|
|
|
' Bottom
|
|
Dim BottomType As String = SearchKeyValue(FileContent(Index), K_BOTTOM)
|
|
If String.IsNullOrEmpty(BottomType) Then
|
|
If Not SearchKey(FileContent(Index), K_BOTTOM) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.BottomType = BottomType
|
|
Index += 1
|
|
End If
|
|
|
|
Dim BottomMachining As String = SearchKeyValue(FileContent(Index), K_MACHINING)
|
|
If String.IsNullOrEmpty(BottomMachining) Then
|
|
If Not SearchKey(FileContent(Index), K_MACHINING) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.BottomMachining = ConvertStringToBoolean(BottomMachining)
|
|
Index += 1
|
|
End If
|
|
|
|
Dim BottomOverMaterial As String = SearchKeyValue(FileContent(Index), K_OVERMATERAL)
|
|
If String.IsNullOrEmpty(BottomOverMaterial) Then
|
|
If Not SearchKey(FileContent(Index), K_OVERMATERAL) Then Return -1
|
|
Index += 1
|
|
Else
|
|
m_Door.BottomOverMaterial = BottomOverMaterial
|
|
Index += 1
|
|
End If
|
|
|
|
Return Index
|
|
End Function
|
|
|
|
' restituisce il nome della componenente
|
|
Public Function DDFGetCompoName(ByRef DdfList As List(Of String), ByRef LastIndex As Integer) As String
|
|
Dim CompoName As String = String.Empty
|
|
Dim Index As Integer
|
|
For Index = LastIndex To DdfList.Count()
|
|
If LTrim(DdfList.Item(Index)) = DdfList.Item(Index) Then
|
|
Dim sItem() As String = DdfList.Item(Index).Split(":".ToCharArray)
|
|
CompoName = sItem(0)
|
|
End If
|
|
Next
|
|
Return CompoName
|
|
End Function
|
|
|
|
|
|
#End Region ' Lettura ddf
|
|
|
|
'Genero la lista di parametri di ogni compo che vedo a video
|
|
Public Function GenerateCompolistDDF(Compo As Compo) As List(Of String)
|
|
Dim CompoListDDF As New List(Of String)
|
|
CompoListDDF.Add(Compo.NameDDF & ":")
|
|
'aggiungo le combobox
|
|
If Compo.ComboBox1Visibility = Visibility.Visible Then
|
|
CompoListDDF.Add(ConstCompo.K_SPACE3 & "- " & Compo.ComboBox1DDFName & ": " & If(Not Path.HasExtension(Compo.ComboBox1SelItem), Compo.ComboBox1ListDDF.Item(Compo.ComboBox1List.IndexOf(Compo.ComboBox1SelItem)), Compo.ComboBox1SelItem.Replace(Path.GetExtension(Compo.ComboBox1SelItem), "")))
|
|
End If
|
|
If Compo.ComboBox2Visibility = Visibility.Visible Then
|
|
CompoListDDF.Add(ConstCompo.K_SPACE5 & Compo.ComboBox2DDFName & ": " & If(Not Path.HasExtension(Compo.ComboBox2SelItem), Compo.ComboBox2ListDDF.Item(Compo.ComboBox2List.IndexOf(Compo.ComboBox2SelItem)), Compo.ComboBox2SelItem.Replace(Path.GetExtension(Compo.ComboBox2SelItem), "")))
|
|
End If
|
|
If Compo.ComboBox3Visibility = Visibility.Visible Then
|
|
CompoListDDF.Add(ConstCompo.K_SPACE5 & Compo.ComboBox3DDFName & ": " & If(Not Path.HasExtension(Compo.ComboBox3SelItem), Compo.ComboBox3ListDDF.Item(Compo.ComboBox3List.IndexOf(Compo.ComboBox3SelItem)), Compo.ComboBox3SelItem.Replace(Path.GetExtension(Compo.ComboBox3SelItem), "")))
|
|
End If
|
|
'aggiungo le textbox
|
|
Dim dVal As Double = 0
|
|
If Compo.TextBox1Visibility = Visibility.Visible Then
|
|
StringToDouble(Compo.TextBox1Value, dVal)
|
|
CompoListDDF.Add(ConstCompo.K_SPACE5 & Compo.TextBox1DDFName & ": " & DoubleToString(dVal, 3))
|
|
End If
|
|
If Compo.TextBox2Visibility = Visibility.Visible Then
|
|
StringToDouble(Compo.TextBox2Value, dVal)
|
|
CompoListDDF.Add(ConstCompo.K_SPACE5 & Compo.TextBox2DDFName & ": " & DoubleToString(dVal, 3))
|
|
End If
|
|
If Compo.TextBox3Visibility = Visibility.Visible Then
|
|
StringToDouble(Compo.TextBox3Value, dVal)
|
|
CompoListDDF.Add(ConstCompo.K_SPACE5 & Compo.TextBox3DDFName & ": " & DoubleToString(dVal, 3))
|
|
End If
|
|
If Compo.TextBox4Visibility = Visibility.Visible Then
|
|
StringToDouble(Compo.TextBox4Value, dVal)
|
|
CompoListDDF.Add(ConstCompo.K_SPACE5 & Compo.TextBox4DDFName & ": " & DoubleToString(dVal, 3))
|
|
End If
|
|
If Compo.TextBox5Visibility = Visibility.Visible Then
|
|
StringToDouble(Compo.TextBox5Value, dVal)
|
|
CompoListDDF.Add(ConstCompo.K_SPACE5 & Compo.TextBox5DDFName & ": " & DoubleToString(dVal, 3))
|
|
End If
|
|
If Compo.SpecialTextBox1Visibility = Visibility.Visible Then
|
|
StringToDouble(Compo.SpecialTextBox1Value, dVal)
|
|
CompoListDDF.Add(ConstCompo.K_SPACE5 & Compo.SpecialTextBox1DDFName & ": " & DoubleToString(dVal, 3))
|
|
End If
|
|
' aggiungo una riga vuota
|
|
CompoListDDF.Add("")
|
|
Return CompoListDDF
|
|
End Function
|
|
End Module
|