00784e5477
- migliorie varie a lettura/scrittura.
194 lines
7.4 KiB
VB.net
194 lines
7.4 KiB
VB.net
Imports System.Collections.ObjectModel
|
|
Imports System.Globalization
|
|
Imports EgtUILib
|
|
Imports System.Text.RegularExpressions
|
|
Imports System.IO
|
|
|
|
Public Module Utility
|
|
Public Function SearchFileConfig(ByRef FrameCompoFile As String, ByRef FrameCompoFileConfig As String) As Boolean
|
|
Dim bFileConfig As Boolean = False
|
|
FrameCompoFile = IniFile.m_CompoDir & "\" & FrameCompoFile
|
|
FrameCompoFileConfig = FrameCompoFile
|
|
If Not File.Exists(FrameCompoFileConfig) Then
|
|
FrameCompoFileConfig = FrameCompoFileConfig & ".lua"
|
|
End If
|
|
If File.Exists(FrameCompoFileConfig) Then
|
|
FrameCompoFileConfig = FrameCompoFileConfig.Remove(FrameCompoFileConfig.LastIndexOf("\"))
|
|
While Not bFileConfig And Not FrameCompoFileConfig.Count < 2
|
|
Dim CurrDirectory() As String = Directory.GetFiles(FrameCompoFileConfig)
|
|
Dim Index As Integer = 0
|
|
FrameCompoFileConfig &= "\" & ConstCompo.CONFIGINI_FILE_NAME
|
|
For Index = 0 To CurrDirectory.Count - 1
|
|
If CurrDirectory(Index) = FrameCompoFileConfig Then
|
|
bFileConfig = True
|
|
Exit While
|
|
End If
|
|
Next
|
|
FrameCompoFileConfig = FrameCompoFileConfig.Remove(FrameCompoFileConfig.LastIndexOf("\"))
|
|
FrameCompoFileConfig = FrameCompoFileConfig.Remove(FrameCompoFileConfig.LastIndexOf("\"))
|
|
End While
|
|
End If
|
|
Return bFileConfig
|
|
End Function
|
|
|
|
' aggiuge un asterisco al nome dell'assemblato da stampare nel bottone
|
|
Public Function SetNameCurrAssemblyAsNew(ByVal value As String) As String
|
|
If Not IsNothing(value) Then
|
|
If Not value.Contains("*") Then
|
|
If value.EndsWith(".ddf") Then
|
|
value = value.Insert(value.Count - 4, "*")
|
|
End If
|
|
End If
|
|
End If
|
|
Return value
|
|
End Function
|
|
|
|
' elimina l'asterisco dal nome dell'assemblato
|
|
Public Function SetNameCurrAssemblyAsSaved(ByVal value As String) As String
|
|
If Not IsNothing(value) Then
|
|
If value.Contains("*") Then
|
|
value = value.Remove(value.IndexOf("*"))
|
|
value &= DDF_EXTENSION
|
|
End If
|
|
End If
|
|
Return value
|
|
End Function
|
|
|
|
Friend Function StringToChar(ByVal sValue As String) As Char()
|
|
Dim cValue(sValue.Count) As Char
|
|
For Index As Integer = 0 To sValue.Count - 1
|
|
cValue(Index) = sValue(Index)
|
|
Next
|
|
Return cValue
|
|
End Function
|
|
|
|
Friend Function CharToString(ByVal cValue() As Char, ByVal sValue As String) As String
|
|
sValue = String.Empty
|
|
For Index As Integer = 0 To cValue.Count - 1
|
|
sValue &= cValue(Index)
|
|
Next
|
|
Return sValue
|
|
End Function
|
|
|
|
Friend Function DoubleToString(ByVal dVal As Double, ByVal nNumDec As Integer) As String
|
|
Dim sFormat As String = "F" + Math.Abs(nNumDec).ToString()
|
|
Dim sVal As String = dVal.ToString(sFormat, CultureInfo.InvariantCulture)
|
|
If nNumDec > 0 Then
|
|
Return sVal.TrimEnd("0".ToCharArray()).TrimEnd(".".ToCharArray)
|
|
Else
|
|
Return sVal
|
|
End If
|
|
End Function
|
|
|
|
Friend Function StringToDouble(ByVal sVal As String, ByRef dVal As Double) As Boolean
|
|
Return EgtLuaEvalNumExpr(sVal, dVal)
|
|
End Function
|
|
|
|
Friend Function LenToString(ByVal dVal As Double, ByVal nNumDec As Integer) As String
|
|
Return DoubleToString(EgtToUiUnits(dVal), nNumDec)
|
|
End Function
|
|
|
|
Friend Function StringToLen(ByVal sVal As String, ByRef dVal As Double) As Boolean
|
|
If EgtLuaEvalNumExpr(sVal, dVal) Then
|
|
dVal = EgtFromUiUnits(dVal)
|
|
Return True
|
|
Else
|
|
Return False
|
|
End If
|
|
End Function
|
|
|
|
' salto gli spazi vuoti fino alla prima riga piena
|
|
Friend Function SkipWhiteSpace(Array() As String, ByRef Index As Integer) As Integer
|
|
While Index < Array.Count
|
|
Dim sTmp As String = RemoveComment(Array(Index))
|
|
If Not String.IsNullOrWhiteSpace(sTmp) Then Exit While
|
|
Index += 1
|
|
End While
|
|
Return Index
|
|
End Function
|
|
|
|
' Converte il valore Boolean in una stringa ON/OFF (attributo machining)
|
|
Friend Function ConvertBooleanToOnOff(bValue As Boolean) As String
|
|
Return If(bValue, DDF_ON, DDF_OFF)
|
|
End Function
|
|
|
|
' converto una stringa in boolean
|
|
Friend Function ConvertOnOffToBoolean(sItem As String) As Boolean
|
|
Return (sItem = DDF_ON)
|
|
End Function
|
|
|
|
Friend Function ConvertMmUnitsToString(bMmUnit As Boolean) As String
|
|
Return If(bMmUnit, "mm", "inches")
|
|
End Function
|
|
|
|
Friend Function ConvertStringToMmUnits(sUnit As String) As Boolean
|
|
If Trim(sUnit) = "mm" Then
|
|
Return True
|
|
ElseIf Trim(sUnit) = "inches" Then
|
|
Return False
|
|
Else
|
|
Return OptionModule.m_bIsMmUnit
|
|
End If
|
|
End Function
|
|
|
|
Friend Sub UpdateUI()
|
|
' Costringo ad aggiornare UI
|
|
Dim nDummy As Integer
|
|
Application.Current.Dispatcher.Invoke(Windows.Threading.DispatcherPriority.Background, _
|
|
New Action(Function() nDummy = 0))
|
|
End Sub
|
|
|
|
Friend Function ConcatErrorString(sErrorList As String, sNewErr As String) As String
|
|
If String.IsNullOrEmpty(sErrorList) Then Return sNewErr
|
|
Return sErrorList & vbCrLf & sNewErr
|
|
End Function
|
|
|
|
Friend Sub ClearObservableCollection(Of T)(Ob As ObservableCollection(Of T))
|
|
For Index = Ob.Count - 1 To 0 Step -1
|
|
Ob.RemoveAt(Index)
|
|
Next
|
|
End Sub
|
|
|
|
Friend Sub GetDirectoryCompoFiles(DirectoryPath As String, ByRef FileList As List(Of String))
|
|
GetDirectoryCompoFiles(DirectoryPath, DirectoryPath, FileList)
|
|
End Sub
|
|
|
|
Private Sub GetDirectoryCompoFiles(DirectoryPath As String, BaseDirectory As String, ByRef FileList As List(Of String))
|
|
Dim SubDir() As String = Directory.GetDirectories(DirectoryPath)
|
|
For Index = 0 To SubDir.Count - 1
|
|
GetDirectoryCompoFiles(SubDir(Index), BaseDirectory, FileList)
|
|
Next
|
|
Dim Files() As String = Directory.GetFiles(DirectoryPath)
|
|
For Index = 0 To Files.Count - 1
|
|
Dim FileExt As String = Path.GetExtension(Files(Index)).ToLower()
|
|
' Se file lua o disegni nge
|
|
If FileExt = LUA_EXTENSION Or FileExt = NGE_EXTENSION Then
|
|
' Salto il file di Matching tra componenti
|
|
If Not Files(Index).Contains(MATCHING_FILE_NAME) Then
|
|
' Elimino il direttorio base dei componenti
|
|
Dim sFile As String = Files(Index).Replace(BaseDirectory & "\", "")
|
|
' Elimino estensione lua
|
|
If FileExt = LUA_EXTENSION Then sFile = Path.ChangeExtension(sFile, Nothing)
|
|
' Inserisco in lista
|
|
FileList.Add(sFile)
|
|
End If
|
|
End If
|
|
Next
|
|
End Sub
|
|
|
|
End Module
|
|
|
|
Public Class SplitConverter
|
|
Implements IValueConverter
|
|
|
|
Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
|
|
Dim dValue As Double = CDbl(value)
|
|
Dim nParam As Integer = CInt(parameter)
|
|
Return dValue / nParam
|
|
End Function
|
|
|
|
Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
|
|
Throw New NotImplementedException
|
|
End Function
|
|
|
|
End Class |