8 Commits

Author SHA1 Message Date
Nicola Pievani 02b979c7c0 Merge branch 'master' into develop 2023-10-10 18:55:18 +02:00
Nicola Pievani 0e4609ba9e Correzione gestione Inch decimali e cambio versione 2023-10-10 18:54:46 +02:00
NicolaP 3c3a858b34 Merge branch 'master' into develop 2023-02-16 15:48:38 +01:00
NicolaP 25f5365241 Aggiornamento versione 2.5b2 2023-02-16 15:48:22 +01:00
NicolaP b0dc763246 Merge branch 'develop' 2023-02-16 15:45:45 +01:00
NicolaP 3bb7510e13 Gestione espressioni in Inch 2023-02-16 15:45:19 +01:00
NicolaP c11c3c0195 Merge branch 'develop' 2023-02-06 14:40:54 +01:00
NicolaP 883b777c5f Migliorata scrittura dati in frazione 2023-02-06 14:40:39 +01:00
3 changed files with 96 additions and 30 deletions
+2 -2
View File
@@ -223,7 +223,7 @@ Public Class EgtCalculator
' La calcolatrice in pollici deve essere abilitata solo se programma NON in MM e IsLength = True
m_IsLength = m_IsLength And Not EgtUiUnitsAreMM()
If m_IsLength Then
If m_IsLength AndAlso nCurrFractionPattern <> FractionPattern.None Then
DotBtn.Visibility = Visibility.Collapsed
BackspaceBtn.Visibility = Visibility.Collapsed
FeetBtn.Visibility = Visibility.Visible
@@ -362,7 +362,7 @@ Public Class EgtCalculator
Dim bOk As Boolean = False
' se impostato per dati in frazioni
Dim sDecimal As String = String.Empty
If StringFractionToStringDecimal(ValueTxBx.Text, sDecimal) Then
If nCurrFractionPattern <> FractionPattern.None AndAlso StringFractionToStringDecimal(ValueTxBx.Text, sDecimal) Then
bOk = EgtUILib.EgtLuaEvalNumExpr(sDecimal, m_DoubleResult)
Else
bOk = EgtUILib.EgtLuaEvalNumExpr(ValueTxBx.Text, m_DoubleResult)
+92 -26
View File
@@ -47,7 +47,7 @@ Public Module FractionStringConverter
sFraction = DoubleToString(dRound, 0) & "/" & DoubleToString(dBase, 0)
End If
' sVal: dFeet'dInteger"sFraction --- dInteger sFraction
Return WriteFraction(dInteger, sFraction)
Return WriteFraction(sSign, dInteger, sFraction)
End Function
' trasforma il valore da pollici a piedi
@@ -60,27 +60,38 @@ Public Module FractionStringConverter
End Sub
' stampa dati in funzione del pattern dichiarato
Private Function WriteFraction(ByVal dInches As Double, sFraction As String) As String
Private Function WriteFraction(ByVal sSign As String, ByVal dInches As Double, sFraction As String) As String
Dim sVal As String = String.Empty
Select Case nCurrFractionPattern
Case FractionPattern.Feet_Inches
Dim dFeet As Double = 0
ConvertInchesToFeet(dFeet, dInches)
If dFeet > 0 Then
If dFeet <> 0 Then
sVal = String.Format("{0}'{1}""{2}", DoubleToString(dFeet, 0), DoubleToString(dInches, 0), sFraction).Trim
Else
sVal = String.Format("{0}""{1}", DoubleToString(dInches, 0), sFraction).Trim
If dInches <> 0 Then
sVal = String.Format("{0}""{1}", DoubleToString(dInches, 0), sFraction).Trim
Else
sVal = String.Format("{0}", sFraction).Trim
End If
End If
Case FractionPattern.Inches
sVal = DoubleToString(dInches, 0) & " " & sFraction
sVal = String.Format("{0}""{1}", DoubleToString(dInches, 0), sFraction).Trim
If dInches <> 0 Then
sVal = String.Format("{0}""{1}", DoubleToString(dInches, 0), sFraction).Trim
Else
sVal = String.Format("{0}", sFraction).Trim
End If
End Select
If Not String.IsNullOrEmpty(sVal) Then
sVal = sSign & sVal
End If
Return sVal
End Function
' riceve la stringa sorgente e restituisce la nuova strunga in formato decimale (senza eseguire conversioni di unità)
Public Function StringFractionToStringDecimal(sVal As String, ByRef sValConverted As String) As Boolean
Public Function OldStringFractionToStringDecimal(sVal As String, ByRef sValConverted As String) As Boolean
Dim dVal As Double = 0
Dim bNegativeValue As Boolean = False
' dato in ingresso: sVal = 2'3"23/32
Dim sFeet As String = String.Empty
Dim sFeetPattern As String = "(.*?)(?=')"
@@ -159,7 +170,11 @@ Public Module FractionStringConverter
' calcolo il valore decimale dell'espressione
If bOkFeet And bOkInch And bOkFraction Then
dVal = dFeet * 12 + dInch + dFraction
If dFeet < 0 OrElse dInch < 0 Or dFraction < 0 Then
dVal = -(Math.Abs(dFeet) * 12 + Math.Abs(dInch) + Math.Abs(dFraction))
Else
dVal = dFeet * 12 + dInch + dFraction
End If
sValConverted = DoubleToString(dVal, 4)
Return True
Else
@@ -167,31 +182,82 @@ Public Module FractionStringConverter
End If
End Function
Public Function MyStringFractionToStringDecimal(sVal As String, ByRef sValConverted As String) As Boolean
Dim sPattern As String = "(-?) *(\d+ */? *\d*')? *(\d* */? *\d+-)? *(\d+ */? *\d* *"")?(\d+ */? *\d*)?"
Public Function StringFractionToStringDecimal(sVal As String, ByRef sValConverted As String) As Boolean
sValConverted = sVal
' (-?) *(\d */? *\d*')? *(\d* */? *\d+-)? *(\d */? *\d* *""?)? *(\d */? *\d*)?
Dim sPattern As String = "(-?) *(\d */? *\d*')?( *(?(?=\d+ */ *\d+)\d+ */ *\d+|\d+)""?)*"
Dim MyMatchCollection As MatchCollection = Regex.Matches(sVal, sPattern)
For Each MyMatch As Match In MyMatchCollection
' Loop over captures.
Dim bValueExists As Boolean = False
Dim bNegative As Boolean = False
Dim dFeet As Double = 0
Dim bFeet As Boolean = True
Dim dInch As Double = 0
Dim bInch As Boolean = True
Dim dFraction As Double = 0
Dim bFraction As Boolean = True
Dim sCurrValue As String = String.Empty
Dim sCurrValueConverted As String = String.Empty
Dim dCurrValueConverted As Double = 0
For Each MyGroup As Capture In MyMatch.Captures
For GroupIndex As Integer = 0 To MyMatch.Groups.Count - 1
Dim MyGroup As Group = MyMatch.Groups(GroupIndex)
Dim sGroupVal As String = MyGroup.Value
Select Case MyGroup.Index
Case 1
' riconosco il segno "-" ad inizio stringa
Case 2
' riconosco il valore di Feet " ' "
Case 3
' ...?...
Case 4
' riconosco il valore di Inch " "" "
Case 5
' riconosco il valore di frazione
End Select
' verifico che il gruppo non sia vuoto
If Not String.IsNullOrEmpty(sGroupVal) Or Not String.IsNullOrWhiteSpace(sGroupVal) Then
Select Case GroupIndex
Case 0
' se il valore è vuoto allora passo a prossimo Match
If String.IsNullOrEmpty(sGroupVal.Trim) Or String.IsNullOrWhiteSpace(sGroupVal.Trim) Then
Exit For
End If
' salvo il valore del membro dell'espressione che deve essere valutato
sCurrValue = sGroupVal
bValueExists = True
Case 1
' riconosco il segno "-" ad inizio stringa
bNegative = True
Case 2
' riconosco il valore di Feet " ' "
sGroupVal = sGroupVal.Replace("'"c, "")
bFeet = StringToDouble(sGroupVal, dFeet)
Case 3
For CaptureIndex As Integer = 0 To MyGroup.Captures.Count - 1
Dim MyCapture As Capture = MyGroup.Captures(CaptureIndex)
Dim sCapture As String = MyCapture.Value
Select Case CaptureIndex
Case 0
' riconosco il valore in pollici
sCapture = sCapture.Replace(""""c, "")
bInch = StringToDouble(sCapture, dInch)
Case 1
' riconosco il valore di frazione
bFraction = StringToDouble(sCapture, dFraction)
End Select
Next
End Select
End If
Next
Next
If bValueExists And bFeet And bInch And bFraction Then
' ricavo il valore decimale
dCurrValueConverted = dFeet * 12 + dInch + dFraction
If bNegative Then dCurrValueConverted = -dCurrValueConverted
sCurrValueConverted = DoubleToString(dCurrValueConverted, 4)
' sostituisco il valore calcolato nell'espressione iniziale
Dim nStartIndex As Integer = sValConverted.IndexOf(sCurrValue)
sValConverted = sValConverted.Remove(nStartIndex, sCurrValue.Count).Insert(nStartIndex, sCurrValueConverted)
End If
' passo allavalutazione del prossimo membro dell'espressione
Next
Dim dValueConverted As Double = 0
If StringToDouble(sValConverted, dValueConverted) Then
sValConverted = DoubleToString(dValueConverted, 4)
Else
' Errore lettura stringa: sCurrVal non è convertibile
Return False
End If
Return True
End Function
+2 -2
View File
@@ -61,5 +61,5 @@ Imports System.Windows
' by using the '*' as shown below:
' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("2.5.2.1")>
<Assembly: AssemblyFileVersion("2.5.2.1")>
<Assembly: AssemblyVersion("2.5.10.1")>
<Assembly: AssemblyFileVersion("2.5.10.1")>