Gestione calcolatrice per misure non Inch

This commit is contained in:
NicolaP
2023-01-23 16:46:20 +01:00
parent 0b2b071ff9
commit 7f0769c5aa
4 changed files with 105 additions and 11 deletions
+15 -4
View File
@@ -26,7 +26,9 @@
<Grid x:Name="TitleGrid" Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.25*"/>
<ColumnDefinition Width="4.5*"/>
<ColumnDefinition Width="3.5*"/>
<ColumnDefinition Width="0.25*"/>
<ColumnDefinition Width="0.75*"/>
<ColumnDefinition Width="0.25*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
@@ -38,6 +40,11 @@
<TextBox x:Name="ValueTxBx" Grid.Column="1" Grid.Row="1" TextAlignment="Right"
FontSize="{DynamicResource EgtCalculator_FontSize}"/>
<Button x:Name="BackspaceLenBtn" Grid.Column="3" Grid.ColumnSpan="2"
Grid.Row="0" Grid.RowSpan="3" BorderBrush="{DynamicResource EgtWPFLib_KeyboardBorderBrush}" Background="{DynamicResource EgtWPFLib_KeyboardButtonColor}" Foreground="{DynamicResource EgtWPFLib_KeyboardTextColor}">
<Image Source="{DynamicResource DeleteArrowImg}" Style="{DynamicResource ButtonIcon}"/>
</Button>
</Grid>
<Grid Grid.Row="1" >
@@ -61,9 +68,9 @@
Content="8" BorderBrush="{DynamicResource EgtWPFLib_KeyboardBorderBrush}" Background="{DynamicResource EgtWPFLib_KeyboardButtonColor}" Foreground="{DynamicResource EgtWPFLib_KeyboardTextColor}"/>
<Button x:Name="NineBtn" Grid.Column="2" Grid.Row="0" FontSize="{DynamicResource EgtCalculator_FontSize}"
Content="9" BorderBrush="{DynamicResource EgtWPFLib_KeyboardBorderBrush}" Background="{DynamicResource EgtWPFLib_KeyboardButtonColor}" Foreground="{DynamicResource EgtWPFLib_KeyboardTextColor}"/>
<Button x:Name="MinusBtn" Grid.Column="3" Grid.Row="0" FontSize="{DynamicResource EgtCalculator_FontSize}"
<Button x:Name="MinusBtn" Grid.Column="4" Grid.Row="0" FontSize="{DynamicResource EgtCalculator_FontSize}"
Content="-" BorderBrush="{DynamicResource EgtWPFLib_KeyboardBorderBrush}" Background="{DynamicResource EgtWPFLib_KeyboardButtonColor}" Foreground="{DynamicResource EgtWPFLib_KeyboardTextColor}"/>
<Button x:Name="BackspaceBtn" Grid.Column="4" Grid.Row="0" BorderBrush="{DynamicResource EgtWPFLib_KeyboardBorderBrush}" Background="{DynamicResource EgtWPFLib_KeyboardButtonColor}" Foreground="{DynamicResource EgtWPFLib_KeyboardTextColor}">
<Button x:Name="BackspaceBtn" Grid.Column="3" Grid.Row="0" BorderBrush="{DynamicResource EgtWPFLib_KeyboardBorderBrush}" Background="{DynamicResource EgtWPFLib_KeyboardButtonColor}" Foreground="{DynamicResource EgtWPFLib_KeyboardTextColor}">
<Image Source="{DynamicResource DeleteArrowImg}" Style="{DynamicResource ButtonIcon}"/>
</Button>
<Button x:Name="FourBtn" Grid.Column="0" Grid.Row="1" FontSize="{DynamicResource EgtCalculator_FontSize}"
@@ -88,7 +95,11 @@
Content="0" BorderBrush="{DynamicResource EgtWPFLib_KeyboardBorderBrush}" Background="{DynamicResource EgtWPFLib_KeyboardButtonColor}" Foreground="{DynamicResource EgtWPFLib_KeyboardTextColor}"/>
<Button x:Name="DotBtn" Grid.Column="1" Grid.Row="3" FontSize="{DynamicResource EgtCalculator_FontSize}"
Content="." BorderBrush="{DynamicResource EgtWPFLib_KeyboardBorderBrush}" Background="{DynamicResource EgtWPFLib_KeyboardButtonColor}" Foreground="{DynamicResource EgtWPFLib_KeyboardTextColor}"/>
<Button x:Name="EvaluateBtn" Grid.Column="2" Grid.Row="3" FontSize="{DynamicResource EgtCalculator_FontSize}"
<Button x:Name="FeetBtn" Grid.Column="1" Grid.Row="3" FontSize="{DynamicResource EgtCalculator_FontSize}"
Content="'" BorderBrush="{DynamicResource EgtWPFLib_KeyboardBorderBrush}" Background="{DynamicResource EgtWPFLib_KeyboardButtonColor}" Foreground="{DynamicResource EgtWPFLib_KeyboardTextColor}"/>
<Button x:Name="InchesBtn" Grid.Column="2" Grid.Row="3" FontSize="{DynamicResource EgtCalculator_FontSize}"
Content="''" BorderBrush="{DynamicResource EgtWPFLib_KeyboardBorderBrush}" Background="{DynamicResource EgtWPFLib_KeyboardButtonColor}" Foreground="{DynamicResource EgtWPFLib_KeyboardTextColor}"/>
<Button x:Name="EvaluateBtn" Grid.Column="3" Grid.Row="0" FontSize="{DynamicResource EgtCalculator_FontSize}"
Content="=" BorderBrush="{DynamicResource EgtWPFLib_KeyboardBorderBrush}" Background="{DynamicResource EgtWPFLib_KeyboardButtonColor}" Foreground="{DynamicResource EgtWPFLib_KeyboardTextColor}"/>
<Button x:Name="VBtn" Grid.Column="3" Grid.Row="3" IsDefault="True" BorderBrush="{DynamicResource EgtWPFLib_KeyboardBorderBrush}" Background="{DynamicResource EgtWPFLib_KeyboardButtonColor}" Foreground="{DynamicResource EgtWPFLib_KeyboardTextColor}">
<Image Source="{DynamicResource VImg}" Style="{DynamicResource ButtonIcon}"/>
+47 -4
View File
@@ -133,12 +133,13 @@ Public Class EgtCalculator
'Me.Left = Owner.Left + (Owner.Width / 2 - Me.Width / 2)
End Sub
Sub New(Owner As Window, Width As Double, WidthType As WidthType, TextBoxBase As Primitives.TextBoxBase)
Sub New(Owner As Window, Width As Double, WidthType As WidthType, TextBoxBase As Primitives.TextBoxBase, Optional IsLength As Boolean = False)
bIsActive = True
m_Owner = Owner
m_SourceTxBx = TextBoxBase
m_Width = Width
m_WidthType = WidthType
m_IsLength = IsLength
InitializeComponent()
If InitializeEgtWPFLib.ResourceDictionary = 0 Then
Dim rd As ResourceDictionary = New ResourceDictionary()
@@ -189,6 +190,17 @@ Public Class EgtCalculator
#Region "Control lifetime events"
' DependencyProperty aggiuntive per gestire la tastiera
Private m_IsLength As Boolean = True
Public Property IsLength As Boolean
Get
Return m_IsLength
End Get
Set(value As Boolean)
m_IsLength = value
End Set
End Property
Private Sub EgtCalculator_Initialized(sender As Object, e As EventArgs) Handles Me.Initialized
'Calcolo dimensioni e posizione della finestra
@@ -208,6 +220,31 @@ Public Class EgtCalculator
Me.Width = m_Width
End Select
' 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
DotBtn.Visibility = Visibility.Collapsed
BackspaceBtn.Visibility = Visibility.Collapsed
FeetBtn.Visibility = Visibility.Visible
InchesBtn.Visibility = Visibility.Visible
BackspaceLenBtn.Visibility = Visibility.Visible
EvaluateBtn.SetValue(Grid.ColumnProperty, 3)
EvaluateBtn.SetValue(Grid.RowProperty, 0)
ValueTxBx.SetValue(Grid.ColumnSpanProperty, 1)
Else
DotBtn.Visibility = Visibility.Visible
BackspaceBtn.Visibility = Visibility.Visible
FeetBtn.Visibility = Visibility.Collapsed
InchesBtn.Visibility = Visibility.Collapsed
BackspaceLenBtn.Visibility = Visibility.Collapsed
EvaluateBtn.SetValue(Grid.ColumnProperty, 2)
EvaluateBtn.SetValue(Grid.RowProperty, 3)
ValueTxBx.SetValue(Grid.ColumnSpanProperty, 3)
End If
End Sub
Private Sub EgtCalculator_Loaded(sender As Object, e As EventArgs) Handles Me.Loaded
@@ -233,7 +270,7 @@ Public Class EgtCalculator
End Sub
Private Sub NumberBtn_Click(sender As Object, e As RoutedEventArgs) Handles OneBtn.Click, TwoBtn.Click, ThreeBtn.Click, FourBtn.Click, FiveBtn.Click, SixBtn.Click, SevenBtn.Click, EightBtn.Click, NineBtn.Click, ZeroBtn.Click,
PlusBtn.Click, MinusBtn.Click, DotBtn.Click, TimesBtn.Click, DividedBtn.Click
PlusBtn.Click, MinusBtn.Click, DotBtn.Click, InchesBtn.Click, FeetBtn.Click, TimesBtn.Click, DividedBtn.Click
If m_bErrorState Then
m_bErrorState = False
ValueTxBx.Foreground = Brushes.Black
@@ -291,6 +328,12 @@ Public Class EgtCalculator
Case DotBtn.Name
Key = "."
Return True
Case InchesBtn.Name
Key = """"
Return True
Case FeetBtn.Name
Key = "'"
Return True
Case TimesBtn.Name
Key = "*"
Return True
@@ -301,7 +344,7 @@ Public Class EgtCalculator
Return False
End Function
Private Sub BackspaceBtn_Click(sender As Object, e As RoutedEventArgs) Handles BackspaceBtn.Click
Private Sub BackspaceBtn_Click(sender As Object, e As RoutedEventArgs) Handles BackspaceBtn.Click, BackspaceLenBtn.Click
ValueTxBx.Focus()
Dim eventArgs As New KeyEventArgs(Keyboard.PrimaryDevice, New HwndSource(0, 0, 0, 0, 0, "", IntPtr.Zero), 0, Key.Back) With {
.RoutedEvent = Keyboard.KeyDownEvent
@@ -326,7 +369,7 @@ Public Class EgtCalculator
End If
If bOk Then
If nCurrFractionPattern <> FractionPattern.None And Not EgtUiUnitsAreMM() Then
If nCurrFractionPattern <> FractionPattern.None And Not EgtUiUnitsAreMM() And m_IsLength Then
ValueTxBx.Text = DoubleToStringFraction(m_DoubleResult, dPrecision)
Else
ValueTxBx.Text = DoubleToString(m_DoubleResult, 6)
+13 -1
View File
@@ -88,6 +88,7 @@ Public Class EgtTextBox
' DependencyProperty aggiuntive per gestire la tastiera
Public Shared ReadOnly KeyboardProperty As DependencyProperty = DependencyProperty.Register("Keyboard", GetType(KeyboardType), GetType(EgtTextBox), New PropertyMetadata(KeyboardType.Null))
Public Property Keyboard As KeyboardType
Get
Return DirectCast(GetValue(KeyboardProperty), KeyboardType)
@@ -105,6 +106,17 @@ Public Class EgtTextBox
element.SetValue(KeyboardProperty, value)
End Sub
' DependencyProperty aggiuntive per gestire la tastiera
Public Shared ReadOnly IsLengthProperty As DependencyProperty = DependencyProperty.Register("IsLength", GetType(Boolean), GetType(EgtTextBox), New PropertyMetadata(True))
Public Property IsLength As Boolean
Get
Return CBool(GetValue(IsLengthProperty))
End Get
Set(value As Boolean)
SetValue(IsLengthProperty, value)
End Set
End Property
Public Shared ReadOnly KeyboardPositionProperty As DependencyProperty = DependencyProperty.Register("KeyboardPosition", GetType(Positions), GetType(EgtTextBox), New PropertyMetadata(Positions.Bottom))
Public Property KeyboardPosition As Positions
@@ -196,7 +208,7 @@ Public Class EgtTextBox
End While
m_Owner = Owner
m_CalculatorPopUp = New EgtPopup
m_Calculator = New EgtWPFLib.EgtCalculator(Owner, GetKeyboardDimension(Me), WidthType.PIXEL, TxBx)
m_Calculator = New EgtWPFLib.EgtCalculator(Owner, GetKeyboardDimension(Me), WidthType.PIXEL, TxBx, IsLength)
m_CalculatorPopUp.Child = m_Calculator
m_CalculatorPopUp.PlacementTarget = TxBx
m_CalculatorPopUp.Placement = PlacementMode.Custom
+30 -2
View File
@@ -83,7 +83,7 @@ Public Module FractionStringConverter
Dim dVal As Double = 0
' dato in ingresso: sVal = 2'3"23/32
Dim sFeet As String = String.Empty
Dim sFeetPattern As String = "^.*?(?=')"
Dim sFeetPattern As String = "(.*?)(?=')"
Dim dFeet As Double = 0
Dim bOkFeet As Boolean = True
Dim bFeetExists As Boolean = False
@@ -135,7 +135,7 @@ Public Module FractionStringConverter
' calcolo il valore decimale dell'espressione
If bOkFeet And bOkInch And bOkFraction Then
dVal = dFeet / 12 + dInch + dFraction
dVal = dFeet * 12 + dInch + dFraction
sValConverted = DoubleToString(dVal, 4)
Return True
Else
@@ -143,4 +143,32 @@ 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*)?"
Dim MyMatchCollection As MatchCollection = Regex.Matches(sVal, sPattern)
For Each MyMatch As Match In MyMatchCollection
' Loop over captures.
For Each MyGroup As Capture In MyMatch.Captures
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
Next
Next
Return True
End Function
End Module