30497d3ee6
- correzioni varie per decrementare sempre il conteggio di istanza all'uscita.
797 lines
32 KiB
VB.net
797 lines
32 KiB
VB.net
Imports System.Collections.ObjectModel
|
|
Imports System.Globalization
|
|
Imports EgtUILib
|
|
Imports System.Text.RegularExpressions
|
|
Imports System.IO
|
|
|
|
Public Module Utility
|
|
Dim PrintMyLog As Boolean = False
|
|
Dim FisrtLog As Boolean = False
|
|
Dim m_CurrLockFile As String
|
|
Dim m_bIsLock As Boolean = False
|
|
Dim m_StopSaving As Boolean = False
|
|
Dim m_nIndexLockFile As Integer = -1
|
|
|
|
Public ReadOnly Property StopSaving As Boolean
|
|
Get
|
|
Return m_StopSaving
|
|
End Get
|
|
End Property
|
|
|
|
#Region "Blocca file/progetto"
|
|
|
|
' CurrFile deve arrivare già senza estensione!
|
|
Private Function GenerateLockFileName(ByVal CurrDirectory As String, Optional ByVal CurrFile As String = "") As String
|
|
' Se in modalità Modifica file DDT allora non bloccare il file
|
|
If OptionModule.AdjustDDT Then
|
|
Return String.Empty
|
|
End If
|
|
If OptionModule.ReadOnlyDDF Then
|
|
Return String.Empty
|
|
End If
|
|
' per bloccare il direttorio
|
|
If String.IsNullOrEmpty(CurrFile) Then
|
|
Return CurrDirectory & "\Lock_Project" & LCK_EXTENSION
|
|
|
|
' per blocccare il file
|
|
Else
|
|
If CurrFile.EndsWith(DDF_EXTENSION) Then
|
|
CurrFile.Replace(DDF_EXTENSION, "")
|
|
End If
|
|
Return CurrDirectory & "\Lock_" & CurrFile & LCK_EXTENSION
|
|
End If
|
|
|
|
End Function
|
|
|
|
Public Function IsFileLocked(ByVal CurrDirectory As String, Optional ByVal CurrFile As String = "", Optional ByVal bSendMsg As Boolean = True) As Boolean
|
|
If String.IsNullOrEmpty(CurrDirectory) Then
|
|
EgtOutLog("Impossible to find directory")
|
|
Return False
|
|
End If
|
|
Dim sLockFile As String = GenerateLockFileName(CurrDirectory, CurrFile)
|
|
Dim bIsLocked As Boolean = False
|
|
Dim FileList As String() = Directory.GetFiles(CurrDirectory)
|
|
|
|
' recurpero il nome del primo file bloccato nel direttorio corrente (se non è specificato un file)
|
|
If String.IsNullOrEmpty(CurrFile) Then
|
|
Try
|
|
sLockFile = FileList.First(Function(x) x.EndsWith(LCK_EXTENSION))
|
|
Catch ex As Exception
|
|
End Try
|
|
End If
|
|
|
|
If File.Exists(sLockFile) Then
|
|
Try
|
|
File.Delete(sLockFile)
|
|
Catch ex As Exception
|
|
bIsLocked = True
|
|
End Try
|
|
End If
|
|
|
|
If bIsLocked Then
|
|
' leggere il nome dell'utente
|
|
Dim UserName As String = ""
|
|
Try
|
|
Dim nIndexFile As Integer = FreeFile()
|
|
FileSystem.FileOpen(nIndexFile, sLockFile, OpenMode.Input, OpenAccess.Read, OpenShare.Shared)
|
|
UserName = FileSystem.LineInput(nIndexFile)
|
|
FileSystem.FileClose(nIndexFile)
|
|
Catch ex As Exception
|
|
End Try
|
|
|
|
If OptionModule.m_SingleDoor Then
|
|
If bSendMsg Then
|
|
Dim sMsg As String = String.Format(EgtMsg(50524), sLockFile, UserName)
|
|
MessageBox.Show(sMsg, EgtMsg(50101), MessageBoxButton.OK, MessageBoxImage.Asterisk)
|
|
End If
|
|
OutLog("File in reading : " & sLockFile)
|
|
Else
|
|
If bSendMsg Then
|
|
' directory in reading by another EgtDOORCreator.
|
|
Dim sMsg As String = String.Format(EgtMsg(50525), sLockFile, UserName)
|
|
MessageBox.Show(sMsg, EgtMsg(50101), MessageBoxButton.OK, MessageBoxImage.Asterisk)
|
|
End If
|
|
OutLog("Directory in reading : " & CurrDirectory)
|
|
End If
|
|
m_StopSaving = True
|
|
'Map.refMainWindowVM.AssemblyManagerControl.Visibility = Visibility.Collapsed
|
|
'Map.refMainWindowVM.SelectedPage = MainWindowVM.ListPageEnum.nNothingSelected
|
|
Return True
|
|
End If
|
|
Return False
|
|
End Function
|
|
|
|
' apertura di un file nel direttorio specificato
|
|
Public Function LockDir(ByVal CurrDirectory As String, Optional ByVal CurrFile As String = "") As Boolean
|
|
If m_bIsLock Then UnLockDir()
|
|
' costruisco il nome del nuovo file di lock
|
|
If Not Directory.Exists(CurrDirectory) Then
|
|
m_bIsLock = False
|
|
Return False
|
|
End If
|
|
m_CurrLockFile = GenerateLockFileName(CurrDirectory, CurrFile)
|
|
m_StopSaving = False
|
|
'If VerifyFileLocked(CurrDirectory, CurrFile) Then Return False
|
|
If Not IsNothing(Map.refMainWindowVM.AssemblyManagerControl) Then
|
|
Map.refMainWindowVM.AssemblyManagerControl.Visibility = Visibility.Visible
|
|
End If
|
|
Try
|
|
Dim NomeUtente As String = Environment.MachineName & "/" & Environment.UserName
|
|
File.WriteAllText(m_CurrLockFile, NomeUtente, New System.Text.UTF8Encoding(False))
|
|
m_nIndexLockFile = FreeFile()
|
|
FileSystem.FileOpen(m_nIndexLockFile, m_CurrLockFile, OpenMode.Append, OpenAccess.ReadWrite, OpenShare.LockWrite)
|
|
m_bIsLock = True
|
|
If String.IsNullOrEmpty(CurrFile) Then
|
|
OutLog("Lock directory : " & m_CurrLockFile)
|
|
Else
|
|
OutLog("Lock file : " & m_CurrLockFile)
|
|
End If
|
|
|
|
Catch ex As Exception
|
|
End Try
|
|
Return True
|
|
End Function
|
|
|
|
' chiusura del file "Lock_Project.txt"
|
|
Public Function UnLockDir() As Boolean
|
|
If Not m_bIsLock Then Return False
|
|
' se esiste chiudo il file lockdir della porta corrente
|
|
Try
|
|
FileClose(m_nIndexLockFile)
|
|
m_bIsLock = False
|
|
OutLog("UnLock : " & m_CurrLockFile)
|
|
Catch ex As Exception
|
|
End Try
|
|
Try
|
|
File.Delete(m_CurrLockFile)
|
|
Catch ex As Exception
|
|
End Try
|
|
Return True
|
|
End Function
|
|
|
|
#End Region ' Blocca file/progetto
|
|
|
|
Public Sub OutLog(sMsg As String)
|
|
FisrtLog = True
|
|
Dim OutLogFile As String = IniFile.m_sTempDir & "\MyOutLog.txt"
|
|
If PrintMyLog Then
|
|
If Not File.Exists(OutLogFile) And FisrtLog Then
|
|
File.WriteAllText(OutLogFile, sMsg & Environment.NewLine)
|
|
FisrtLog = False
|
|
Else
|
|
File.AppendAllText(OutLogFile, sMsg & Environment.NewLine)
|
|
End If
|
|
End If
|
|
EgtOutLog(sMsg)
|
|
End Sub
|
|
|
|
' dato il nome della componete ricerco il file di configurazione associato
|
|
Public Function SearchFileConfig(ByRef FrameCompoFile As String, ByRef FrameCompoFileConfig As String) As Boolean
|
|
Dim CurrDir() As String = FrameCompoFile.Split("\"c)
|
|
' DirettorioCompo\NomeFile -> questa è la struttura minima che posso ricevere, altrimenti è un errore
|
|
If CurrDir.Count > 1 Then
|
|
FrameCompoFileConfig = CurrDir(0) & "\" & ConstCompo.CONFIGINI_FILE_NAME
|
|
' restituisco il percorso completo del file caricato
|
|
FrameCompoFileConfig = IniFile.m_CompoDir & "\" & FrameCompoFileConfig
|
|
Dim Local_File As String = IniFile.m_CompoDir & "\" & FrameCompoFile
|
|
If Not Path.HasExtension(Local_File) Then
|
|
Local_File = Local_File & LUA_EXTENSION
|
|
End If
|
|
If Not File.Exists(Local_File) OrElse Not File.Exists(FrameCompoFileConfig) Then
|
|
Return False
|
|
End If
|
|
Return True
|
|
End If
|
|
Return False
|
|
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 - 1) 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 = ConstGen.PART_FRAME + 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
|
|
|
|
Friend Function SkipWhiteSpaceList(ListOfString As List(Of String), ByRef Index As Integer) As Integer
|
|
While Index < ListOfString.Count
|
|
Dim sTmp As String = RemoveComment(ListOfString(Index))
|
|
If Not String.IsNullOrWhiteSpace(sTmp) Then Exit While
|
|
Index += 1
|
|
End While
|
|
Return Index
|
|
End Function
|
|
|
|
' Verifica se il file/path indicato è ddf (true)
|
|
Friend Function IsCurrentFileDDF(sFileName As String) As Boolean
|
|
Dim IsDDF As Boolean = True
|
|
If Not String.IsNullOrEmpty(sFileName) AndAlso Path.HasExtension(sFileName) Then
|
|
Dim sExtension As String = Path.GetExtension(sFileName)
|
|
If sExtension.ToLower = DDT_EXTENSION Then
|
|
IsDDF = False
|
|
End If
|
|
End If
|
|
Return IsDDF
|
|
End Function
|
|
|
|
#Region "PARAM LUA"
|
|
|
|
' elimina i commenti nel file lua
|
|
Friend Function DeleteLuaComment(sLine As String) As String
|
|
sLine = Trim(sLine)
|
|
If sLine.Contains("--") And Not sLine.Contains(K_MATCHING_FILE) Then
|
|
If sLine.StartsWith("--") Then Return String.Empty
|
|
sLine = Regex.Match(sLine, "\s*(.*?)\s*\--\s*\.*").Groups(1).Value
|
|
Return sLine
|
|
Else
|
|
Return sLine
|
|
End If
|
|
End Function
|
|
|
|
' controllo che il valore in lettura sia una misura
|
|
Friend Function GetMeasure(sValue As String) As String
|
|
Dim dVal As Double = 0.0
|
|
If sValue.Contains("(") And sValue.Contains(")") And sValue.Contains("inch") Then
|
|
sValue = Trim(sValue.Replace("inch", ""))
|
|
If sValue.StartsWith("(") And sValue.EndsWith(")") Then
|
|
Dim ArrayString() As Char = StringToChar(sValue)
|
|
ArrayString(0) = CChar("§")
|
|
ArrayString(ArrayString.Count - 1) = CChar("§")
|
|
sValue = CharToString(ArrayString, sValue)
|
|
sValue = Trim(sValue.Replace("§", ""))
|
|
End If
|
|
If String.IsNullOrEmpty(sValue) Then Return "0.0000"
|
|
' ricevo un valore in inches
|
|
Select Case OptionModule.m_SelectedMeasureUnit
|
|
Case ConstGen.VAL_INCHES ' se la configurazione è inches non faccio conversioni
|
|
If StringToDouble(sValue, dVal) Then
|
|
Return sValue
|
|
Else
|
|
Return "0.0000"
|
|
End If
|
|
Case ConstGen.MM ' se la configurazione è in mm faccio la conevrsione
|
|
If InchesToMm(sValue) Then
|
|
Return sValue
|
|
Else
|
|
Return "0.0000"
|
|
End If
|
|
End Select
|
|
ElseIf sValue.Contains("(") And sValue.Contains(")") And sValue.Contains("mm") Then
|
|
sValue = Trim(sValue.Replace("mm", ""))
|
|
If sValue.StartsWith("(") And sValue.EndsWith(")") Then
|
|
Dim ArrayString() As Char = StringToChar(sValue)
|
|
ArrayString(0) = CChar("§")
|
|
ArrayString(ArrayString.Count - 1) = CChar("§")
|
|
sValue = CharToString(ArrayString, sValue)
|
|
sValue = Trim(sValue.Replace("§", ""))
|
|
End If
|
|
If String.IsNullOrEmpty(sValue) Then Return "0.0000"
|
|
' ricevo un valore in inches
|
|
Select Case OptionModule.m_SelectedMeasureUnit
|
|
Case ConstGen.MM ' se la configurazione è inches non faccio conversioni
|
|
If StringToDouble(sValue, dVal) Then
|
|
Return sValue
|
|
Else
|
|
Return "0.0000"
|
|
End If
|
|
Case ConstGen.VAL_INCHES ' se la configurazione è in mm faccio la conevrsione
|
|
If MmToInches(sValue) Then
|
|
Return sValue
|
|
Else
|
|
Return "0.0000"
|
|
End If
|
|
End Select
|
|
ElseIf sValue.Contains("(") And sValue.Contains(")") And (Not sValue.Contains("inch") Or Not sValue.Contains("mm")) Then
|
|
'sValue = Regex.Match(sValue, "\s*\((.*?)\s*\)\s*\.*").Groups(1).Value
|
|
If String.IsNullOrEmpty(sValue) Then Return "0.0000"
|
|
' ricevo un valore in mm
|
|
Select Case OptionModule.m_SelectedMeasureUnit
|
|
Case ConstGen.VAL_INCHES ' se la configurazione è inches faccio conversioni
|
|
If MmToInches(sValue) Then
|
|
Return sValue
|
|
Else
|
|
Return "0.0000"
|
|
End If
|
|
Case ConstGen.MM ' se la configurazione è in mm non faccio la conevrsione
|
|
If StringToDouble(sValue, dVal) Then
|
|
Return sValue
|
|
Else
|
|
Return "0.0000"
|
|
End If
|
|
End Select
|
|
End If
|
|
' il valore che ricevo è in mm
|
|
Select Case OptionModule.m_SelectedMeasureUnit
|
|
Case ConstGen.VAL_INCHES ' se la configurazione è inches faccio conversione
|
|
If MmToInches(sValue) Then
|
|
Return sValue
|
|
Else
|
|
Return "0.0000"
|
|
End If
|
|
Case ConstGen.MM ' se la configurazione è in mm non faccio la conevrsione
|
|
If StringToDouble(sValue, dVal) Then
|
|
Return sValue
|
|
Else
|
|
Return "0.0000"
|
|
End If
|
|
End Select
|
|
' se non è nessuno dei casi restituisco zero
|
|
Return "0.0000"
|
|
End Function
|
|
|
|
Friend Function InchesToMm(ByRef sMeasure As String) As Boolean
|
|
Dim dVal As Double = 0.0
|
|
If Not StringToDouble(sMeasure, dVal) Then Return False
|
|
dVal = dVal * ONEINCH
|
|
sMeasure = LenToString(dVal, 3)
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function MmToInches(ByRef sMeasure As String) As Boolean
|
|
Dim dVal As Double = 0.0
|
|
If Not StringToDouble(sMeasure, dVal) Then Return False
|
|
'dVal = dVal / ONEINCH
|
|
sMeasure = LenToString(dVal, 4)
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function DirectInchesToMm(ByRef sMeasure As String) As Boolean
|
|
Dim dVal As Double = 0.0
|
|
If Not StringToDouble(sMeasure, dVal) Then Return False
|
|
dVal = dVal * ONEINCH
|
|
sMeasure = DoubleToString(dVal, 3)
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function DirectMmToInches(ByRef sMeasure As String) As Boolean
|
|
Dim dVal As Double = 0.0
|
|
If Not StringToDouble(sMeasure, dVal) Then Return False
|
|
dVal = dVal / ONEINCH
|
|
sMeasure = DoubleToString(dVal, 4)
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function ConvertCurrentUnitMeasure(ByRef sMeasure As String) As Boolean
|
|
If OptionModule.m_SelectedMeasureUnit = ConstGen.VAL_INCHES Then
|
|
' non eseguo nessun tipo di conversione
|
|
Return True
|
|
Else
|
|
' la configurazione è già in mm quindi non devo convertire
|
|
If OptionModule.m_IsMM Then
|
|
Return True
|
|
End If
|
|
Return InchesToMm(sMeasure)
|
|
End If
|
|
Return False
|
|
End Function
|
|
|
|
Friend Function ConvertCheckBox(sValue As String) As Boolean
|
|
If Trim(sValue.ToLower) = "true" Then Return True Else Return False
|
|
End Function
|
|
|
|
' elimina gli apici di una variabile
|
|
Friend Function DeleteSuperScript(sLine As String) As String
|
|
Return sLine.Replace("'"c, " "c)
|
|
End Function
|
|
|
|
Friend Function FindNameParam(sLine As String) As String
|
|
sLine = RegexFunction.GetNameParamInFileTempl(sLine)
|
|
If String.IsNullOrEmpty(sLine) Then Return String.Empty
|
|
Return sLine
|
|
End Function
|
|
|
|
#End Region ' Param lua
|
|
|
|
' conevrsione in lettura dei valori delle textbox nel DoorCreator/HardwareManager
|
|
Friend Function ConvertCompoConfig(ByRef sItems As String, ByRef dControlValue As Double) As Boolean
|
|
Dim dDefaultValue As Double = 0
|
|
If sItems.Contains("$") Then
|
|
sItems = "$"
|
|
Return True
|
|
End
|
|
End If
|
|
If OptionModule.m_SelectedMeasureUnit = ConstGen.VAL_INCHES And Not OptionModule.m_IsMM Then
|
|
' Concordi = Inches
|
|
If StringToLen(sItems, dDefaultValue) AndAlso dDefaultValue < dControlValue Then
|
|
sItems = Trim(sItems)
|
|
Return True
|
|
End If
|
|
ElseIf OptionModule.m_SelectedMeasureUnit = ConstGen.VAL_INCHES And OptionModule.m_IsMM Then
|
|
' Discordi
|
|
If StringToDouble(sItems, dDefaultValue) AndAlso dDefaultValue < dControlValue Then
|
|
MmToInches(sItems)
|
|
Return True
|
|
End If
|
|
ElseIf OptionModule.m_SelectedMeasureUnit = ConstGen.MM And Not OptionModule.m_IsMM Then
|
|
' Discordi
|
|
dControlValue = dControlValue * 25.4
|
|
If StringToLen(sItems, dDefaultValue) AndAlso dDefaultValue < dControlValue Then
|
|
InchesToMm(sItems)
|
|
Return True
|
|
End If
|
|
ElseIf OptionModule.m_SelectedMeasureUnit = ConstGen.MM And OptionModule.m_IsMM Then
|
|
' Concordi = MM
|
|
dControlValue = dControlValue * 25.4
|
|
If StringToLen(sItems, dDefaultValue) AndAlso dDefaultValue < dControlValue Then
|
|
sItems = Trim(sItems)
|
|
Return True
|
|
End If
|
|
End If
|
|
Return False
|
|
End Function
|
|
|
|
Friend Function ConvertToCompoConfig(ByRef sItems As String) As Boolean
|
|
Dim dDefaultValue As Double = 0
|
|
If OptionModule.m_SelectedMeasureUnit = ConstGen.VAL_INCHES And Not OptionModule.m_IsMM Then
|
|
' Concordi = Inches
|
|
If StringToLen(sItems, dDefaultValue) Then
|
|
sItems = Trim(sItems)
|
|
Return True
|
|
End If
|
|
ElseIf OptionModule.m_SelectedMeasureUnit = ConstGen.VAL_INCHES And OptionModule.m_IsMM Then
|
|
' Discordi
|
|
If StringToLen(sItems, dDefaultValue) Then
|
|
InchesToMm(sItems)
|
|
Return True
|
|
End If
|
|
ElseIf OptionModule.m_SelectedMeasureUnit = ConstGen.MM And Not OptionModule.m_IsMM Then
|
|
' Discordi
|
|
If StringToLen(sItems, dDefaultValue) Then
|
|
MmToInches(sItems)
|
|
Return True
|
|
End If
|
|
ElseIf OptionModule.m_SelectedMeasureUnit = ConstGen.MM And OptionModule.m_IsMM Then
|
|
' Concordi = MM
|
|
If StringToLen(sItems, dDefaultValue) Then
|
|
sItems = Trim(sItems)
|
|
Return True
|
|
End If
|
|
End If
|
|
Return False
|
|
End Function
|
|
|
|
Friend Function ConvertDDFValueIntoCurrentUnit(sCurrUnitDDF As String, ByRef sValue As String) As Boolean
|
|
Dim bCurrUnitDDFIsMM As Boolean = ConvertStringToMmUnits(sCurrUnitDDF)
|
|
Dim dDefaultValue As Double = 0
|
|
If OptionModule.m_SelectedMeasureUnit = ConstGen.VAL_INCHES And Not bCurrUnitDDFIsMM Then
|
|
' non eseguo cenversione: Concordi = Inches
|
|
Return True
|
|
ElseIf OptionModule.m_SelectedMeasureUnit = ConstGen.VAL_INCHES And bCurrUnitDDFIsMM Then
|
|
' eseguo conversione: Discordi= MM → Inches
|
|
DirectMmToInches(sValue)
|
|
'InchesToMm(sValue)
|
|
Return True
|
|
ElseIf OptionModule.m_SelectedMeasureUnit = ConstGen.MM And Not bCurrUnitDDFIsMM Then
|
|
' eseguo conversione: Discordi= Inches → MM
|
|
DirectInchesToMm(sValue)
|
|
Return True
|
|
ElseIf OptionModule.m_SelectedMeasureUnit = ConstGen.MM And bCurrUnitDDFIsMM Then
|
|
' non eseguo cenversione: Concordi = MM
|
|
Return True
|
|
End If
|
|
Return False
|
|
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, ConstGen.MM, ConstGen.VAL_INCHES.ToLower)
|
|
End Function
|
|
|
|
Friend Function ConvertStringToMmUnits(sUnit As String) As Boolean
|
|
If Trim(sUnit).ToLower = ConstGen.MM.ToLower Then
|
|
Return True
|
|
ElseIf Trim(sUnit).ToLower = ConstGen.VAL_INCHES.ToLower Then
|
|
Return False
|
|
Else
|
|
Return OptionModule.m_bIsMmUnit
|
|
End If
|
|
End Function
|
|
|
|
' Conversione stringhe con W, H e T in DGD.dW, DGD.dH, DGD.dT e viceversa per lettura/scrittura parametri compo
|
|
Friend Function ConvertFromDGD(sTypeVar As String, sValue As String) As String
|
|
Dim sMyVal As String = sValue
|
|
' se testo numerico, eseguo opportune conversioni per H,W e T
|
|
If sTypeVar = ConstGen.INCHES Or sTypeVar = ConstGen.MM Then
|
|
If OptionModule.m_SelectedMeasureUnit = ConstGen.VAL_INCHES Then
|
|
sMyVal = sMyVal.Replace("W", "(DGD.dW/25.4)")
|
|
sMyVal = sMyVal.Replace("H", "(DGD.dH/25.4)")
|
|
sMyVal = sMyVal.Replace("T", "(DGD.dT/25.4)")
|
|
Else
|
|
sMyVal = sMyVal.Replace("W", "(DGD.dW)")
|
|
sMyVal = sMyVal.Replace("H", "(DGD.dH)")
|
|
sMyVal = sMyVal.Replace("T", "(DGD.dT)")
|
|
End If
|
|
End If
|
|
Return sMyVal
|
|
End Function
|
|
|
|
Friend Function ConvertToDGD(sTypeVar As String, sValue As String) As String
|
|
Dim sMyVal As String = sValue
|
|
' se testo numerico, eseguo opportunbe conversioni per H,W e T
|
|
'If sTypeVar = ConstGen.INCHES Or sTypeVar = ConstGen.MM Then
|
|
' If OptionModule.m_SelectedMeasureUnit = ConstGen.VAL_INCHES Then
|
|
' sMyVal = sMyVal.Replace("(DGD.dW/25.4)", "W")
|
|
' sMyVal = sMyVal.Replace("(DGD.dH/25.4)", "H")
|
|
' sMyVal = sMyVal.Replace("(DGD.dT/25.4)", "T")
|
|
' Else
|
|
' sMyVal = sMyVal.Replace("DGD.dW", "W")
|
|
' sMyVal = sMyVal.Replace("DGD.dH", "H")
|
|
' sMyVal = sMyVal.Replace("DGD.dT", "T")
|
|
' End If
|
|
'End If
|
|
If sMyVal.Contains("25.4") Then
|
|
sMyVal = sMyVal.Replace("(DGD.dW/25.4)", "W")
|
|
sMyVal = sMyVal.Replace("(DGD.dH/25.4)", "H")
|
|
sMyVal = sMyVal.Replace("(DGD.dT/25.4)", "T")
|
|
Else
|
|
sMyVal = sMyVal.Replace("(DGD.dW)", "W")
|
|
sMyVal = sMyVal.Replace("(DGD.dH)", "H")
|
|
sMyVal = sMyVal.Replace("(DGD.dT)", "T")
|
|
End If
|
|
Return sMyVal
|
|
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
|
|
|
|
' costruisco le liste dei file
|
|
Friend Sub GetDirectoryCompoModel(HardwareDirPath As String, FolderList As ObservableCollection(Of CompoBrandDir),
|
|
Optional FrameFolderList As ObservableCollection(Of CompoBrandDir) = Nothing,
|
|
Optional HardwareFolderList As ObservableCollection(Of CompoBrandDir) = Nothing)
|
|
' Nome del direttorio dei componenti
|
|
Dim BaseDirName As String = Path.GetFileName(HardwareDirPath)
|
|
' Carico l'elenco dei file contenuti nei sottodirettori
|
|
Dim FolderArray() As String = Directory.GetDirectories(HardwareDirPath)
|
|
For Each Folder In FolderArray
|
|
Folder = Folder.Replace("/", "\")
|
|
Dim CurrGenFolder As CompoBrandDir = New CompoBrandDir(Folder, BaseDirName)
|
|
GetDirectoryCompoFiles(Folder, CurrGenFolder.ModelFileList, False)
|
|
' genero le liste per il DoorCreator
|
|
If CurrGenFolder.ModelFileList.Count > 0 Then
|
|
If Folder.ToLower.Contains(FRAME_FOLDER) Then
|
|
If Not IsNothing(FrameFolderList) Then FrameFolderList.Add(CurrGenFolder)
|
|
Else
|
|
FolderList.Add(CurrGenFolder)
|
|
End If
|
|
End If
|
|
' genero le liste per l'HardwareManager
|
|
If Not IsNothing(HardwareFolderList) Then
|
|
Dim CurrHardFolder As CompoBrandDir = New CompoBrandDir(Folder, BaseDirName)
|
|
GetDirectoryCompoFiles(Folder, CurrHardFolder.ModelFileList, True)
|
|
If OptionModule.m_ConfigurationSoftware = ConfigType.Assembly Then
|
|
HardwareFolderList.Add(CurrHardFolder)
|
|
Else
|
|
' solo se non sono in modalità assemblato non carico gli elenchi ".frame"
|
|
If Not Folder.ToLower.Contains(FRAME_FOLDER) Then
|
|
HardwareFolderList.Add(CurrHardFolder)
|
|
End If
|
|
End If
|
|
End If
|
|
Next
|
|
' Carico l'elenco dei file contenuti nel direttorio
|
|
Dim FileArray() As String = Directory.GetFiles(HardwareDirPath)
|
|
Dim CurrFolder As CompoBrandDir = Nothing
|
|
Dim CurrFrameFolder As CompoBrandDir = Nothing
|
|
Dim CurrHardwareFolder As CompoBrandDir = Nothing
|
|
For Each File In FileArray
|
|
File = File.Replace("/", "\")
|
|
Dim sExt As String = Path.GetExtension(File).ToLower
|
|
If (sExt = LUA_EXTENSION Or sExt = NGE_EXTENSION) And
|
|
Not File.Contains(MATCHING_FILE_NAME) And Not File.ToLower().Contains("currhardware") Then
|
|
If File.Contains(FRAME_FOLDER) Then
|
|
If IsNothing(CurrFrameFolder) Then
|
|
CurrFrameFolder = New CompoBrandDir(HardwareDirPath, BaseDirName & FRAME_FOLDER)
|
|
If Not IsNothing(FrameFolderList) Then FrameFolderList.Add(CurrFrameFolder)
|
|
End If
|
|
CurrFrameFolder.ModelFileList.Add(If(Path.GetExtension(File).ToLower = NGE_EXTENSION, Path.GetFileName(File), Path.GetFileNameWithoutExtension(File)))
|
|
Else
|
|
If IsNothing(CurrFolder) Then
|
|
CurrFolder = New CompoBrandDir(HardwareDirPath, BaseDirName)
|
|
FolderList.Add(CurrFolder)
|
|
End If
|
|
CurrFolder.ModelFileList.Add(If(Path.GetExtension(File).ToLower = NGE_EXTENSION, Path.GetFileName(File), Path.GetFileNameWithoutExtension(File)))
|
|
If Not File.Contains(NGE_EXTENSION) Then
|
|
If IsNothing(CurrHardwareFolder) Then
|
|
CurrHardwareFolder = New CompoBrandDir(HardwareDirPath, BaseDirName)
|
|
If Not IsNothing(HardwareFolderList) Then HardwareFolderList.Add(CurrHardwareFolder)
|
|
End If
|
|
CurrHardwareFolder.ModelFileList.Add(If(Path.GetExtension(File).ToLower = NGE_EXTENSION, Path.GetFileName(File), Path.GetFileNameWithoutExtension(File)))
|
|
End If
|
|
End If
|
|
End If
|
|
Next
|
|
End Sub
|
|
|
|
Friend Sub GetDirectoryCompoFiles(DirectoryPath As String, ByRef FileList As ObservableCollection(Of String), bRemoveNge As Boolean)
|
|
RecursiveGetDirectoryCompoFiles(DirectoryPath, DirectoryPath, FileList, bRemoveNge)
|
|
End Sub
|
|
|
|
Private Sub RecursiveGetDirectoryCompoFiles(DirectoryPath As String, BaseDirectory As String, ByRef FileList As ObservableCollection(Of String), bRemoveNge As Boolean)
|
|
' File nei sottodirettori
|
|
Dim SubDir() As String = Directory.GetDirectories(DirectoryPath)
|
|
For Index = 0 To SubDir.Count - 1
|
|
RecursiveGetDirectoryCompoFiles(SubDir(Index), BaseDirectory, FileList, bRemoveNge)
|
|
Next
|
|
' File nel direttorio
|
|
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 And Not Files(Index).ToLower().Contains("currhardware")) Or
|
|
(FileExt = NGE_EXTENSION And Not bRemoveNge) 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
|
|
Next
|
|
End Sub
|
|
|
|
End Module
|
|
|
|
Public Class CompoBrandDir
|
|
|
|
Private m_ModelDirGraphic As String
|
|
Public ReadOnly Property ModelDirGraphic As String
|
|
Get
|
|
Return m_ModelDirGraphic
|
|
End Get
|
|
End Property
|
|
|
|
Private m_ModelDir As String
|
|
Public Property ModelDir As String
|
|
Get
|
|
Return m_ModelDir
|
|
End Get
|
|
Set(value As String)
|
|
m_ModelDir = value
|
|
End Set
|
|
End Property
|
|
|
|
Private m_ModelFileList As New ObservableCollection(Of String)
|
|
Public Property ModelFileList As ObservableCollection(Of String)
|
|
Get
|
|
Return m_ModelFileList
|
|
End Get
|
|
Set(value As ObservableCollection(Of String))
|
|
m_ModelFileList = value
|
|
End Set
|
|
End Property
|
|
|
|
Sub New(Model As String, BaseDirName As String)
|
|
m_ModelDir = Model
|
|
m_ModelDirGraphic = RegexFunction.SubStractDirFromPath(Model, BaseDirName)
|
|
If Path.GetFileName(m_ModelDirGraphic) = BaseDirName Then m_ModelDirGraphic = RAD_DIR
|
|
End Sub
|
|
|
|
Sub New(CopyCompoBrandDir As CompoBrandDir, HardwareDirPath As String)
|
|
m_ModelDir = CopyCompoBrandDir.ModelDir
|
|
Dim BaseDirName As String = Path.GetFileName(HardwareDirPath)
|
|
m_ModelDirGraphic = RegexFunction.SubStractDirFromPath(CopyCompoBrandDir.ModelDir, BaseDirName)
|
|
If Path.GetFileName(m_ModelDirGraphic) = BaseDirName Then m_ModelDirGraphic = RAD_DIR
|
|
End Sub
|
|
|
|
End Class
|
|
|
|
Public Class ItemFile
|
|
|
|
Private Property m_FileName As String
|
|
Public Property FileName As String
|
|
Get
|
|
Return m_FileName
|
|
End Get
|
|
Set(value As String)
|
|
m_FileName = value
|
|
End Set
|
|
End Property
|
|
|
|
Private Property m_FileNameVisibility As Visibility = Visibility.Visible
|
|
Public Property FileNameVisibility As Visibility
|
|
Get
|
|
Return m_FileNameVisibility
|
|
End Get
|
|
Set(value As Visibility)
|
|
m_FileNameVisibility = value
|
|
End Set
|
|
End Property
|
|
|
|
Sub New(Name As String, NameVisibility As Visibility)
|
|
m_FileName = Name
|
|
m_FileNameVisibility = NameVisibility
|
|
End Sub
|
|
|
|
End Class |