Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Engineering Notation #2028

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/CalcManager/CEngine/scicomm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,11 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
DisplayNum();
break;

case IDC_ENG:
m_nFE = NumberFormat::Engineering;
DisplayNum();
break;

case IDC_EXP:
if (m_bRecord && !m_fIntegerMode && m_input.TryBeginExponent())
{
Expand Down
1 change: 1 addition & 0 deletions src/CalcManager/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ namespace CalculationManager
CommandGRAD = 323,
CommandDegrees = 324,
CommandHYP = 325,
CommandENG = 326,

CommandNULL = 0,

Expand Down
1 change: 1 addition & 0 deletions src/CalcManager/Header Files/CCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define IDM_RAD 322
#define IDM_GRAD 323
#define IDM_DEGREES 324
#define IDC_ENG 326

#define IDC_HEX IDM_HEX
#define IDC_DEC IDM_DEC
Expand Down
2 changes: 1 addition & 1 deletion src/CalcManager/Ratpack/conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,7 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, NumberFormat format, uint32_t radi
{
if (format == NumberFormat::Engineering)
{
exponent = (eout % 3);
exponent = (3 + (eout % 3)) % 3;
eout -= exponent;
exponent++;

Expand Down
1 change: 1 addition & 0 deletions src/CalcViewModel/Common/CalculatorButtonUser.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace CalculatorApp::ViewModel::Common
Radians = (int)CM::Command::CommandRAD,
Grads = (int)CM::Command::CommandGRAD,
Degrees = (int)CM::Command::CommandDegrees,
Engineering = (int)CM::Command::CommandENG,
OpenParenthesis = (int)CM::Command::CommandOPENP,
CloseParenthesis = (int)CM::Command::CommandCLOSEP,
Pi = (int)CM::Command::CommandPI,
Expand Down
6 changes: 6 additions & 0 deletions src/CalcViewModel/StandardCalculatorViewModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,12 @@ void StandardCalculatorViewModel::FtoEButtonToggled()
OnButtonPressed(NumbersAndOperatorsEnum::FToE);
}

void StandardCalculatorViewModel::EngButton()
{
OnButtonPressed(NumbersAndOperatorsEnum::Engineering);
}


void StandardCalculatorViewModel::HandleUpdatedOperandData(Command cmdenum)
{
DisplayExpressionToken ^ displayExpressionToken = ExpressionTokens->GetAt(m_TokenPosition);
Expand Down
1 change: 1 addition & 0 deletions src/CalcViewModel/StandardCalculatorViewModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ namespace CalculatorApp
void SetOpenParenthesisCountNarratorAnnouncement();
void SwitchAngleType(CalculatorApp::ViewModel::Common::NumbersAndOperatorsEnum num);
void FtoEButtonToggled();
void EngButton();

internal:
void OnPaste(Platform::String ^ pastedString);
Expand Down
43 changes: 27 additions & 16 deletions src/Calculator/Views/CalculatorScientificAngleButtons.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,32 @@
CommandParameter="2"
Content="GRAD"
Visibility="Collapsed"/>
<ToggleButton x:Name="FtoeButton"
Grid.Column="1"
Style="{StaticResource CaptionToggleButtonWithIndicatorStyle}"
Background="{ThemeResource SystemControlBackgroundTransparentBrush}"
common:KeyboardShortcutManager.VirtualKey="{utils:ResourceVirtualKey Name=ftoeButton/[using:CalculatorApp.Common]KeyboardShortcutManager/VirtualKey}"
AutomationProperties.AutomationId="ftoeButton"
AutomationProperties.Name="{utils:ResourceString Name=ftoeButton/[using:Windows.UI.Xaml.Automation]AutomationProperties/Name}"
Checked="FToEButton_Toggled"
Content="F-E"
IsChecked="{x:Bind Model.IsFToEChecked, Mode=OneWay}"
Unchecked="FToEButton_Toggled"
IsEnabled="{x:Bind Model.IsFToEEnabled, Mode=OneWay}">
<ToggleButton.CommandParameter>
<local:NumbersAndOperatorsEnum>FToE</local:NumbersAndOperatorsEnum>
</ToggleButton.CommandParameter>
</ToggleButton>

<Button x:Name="AutoButton"
x:Uid="AutoButton"
Grid.Column="1"
Style="{StaticResource CaptionButtonSmallStyle}"
AutomationProperties.AutomationId="autoButton"
Command="{x:Bind NotationPressed}"
CommandParameter="0"
Content="AUTO"/>
<Button x:Name="SciButton"
x:Uid="SciButton"
Grid.Column="1"
Style="{StaticResource CaptionButtonSmallStyle}"
AutomationProperties.AutomationId="sciButton"
Command="{x:Bind NotationPressed}"
CommandParameter="1"
Content="SCI"
Visibility="Collapsed"/>
<Button x:Name="EngButton"
x:Uid="EngButton"
Grid.Column="1"
Style="{StaticResource CaptionButtonSmallStyle}"
AutomationProperties.AutomationId="engButton"
Command="{x:Bind NotationPressed}"
CommandParameter="2"
Content="ENG"
Visibility="Collapsed"/>
</Grid>
</UserControl>
49 changes: 44 additions & 5 deletions src/Calculator/Views/CalculatorScientificAngleButtons.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ namespace CalculatorApp
[Windows.Foundation.Metadata.WebHostHidden]
public sealed partial class CalculatorScientificAngleButtons
{
public CalculatorScientificAngleButtons()
public CalculatorScientificAngleButtons()
{
m_isErrorVisualState = false;
InitializeComponent();
InitializeComponent();
}

public StandardCalculatorViewModel Model => (StandardCalculatorViewModel)this.DataContext;
Expand Down Expand Up @@ -84,10 +84,49 @@ private void OnAngleButtonPressed(object commandParameter)
}
}

private void FToEButton_Toggled(object sender, RoutedEventArgs e)
public System.Windows.Input.ICommand NotationPressed
{
var viewModel = (StandardCalculatorViewModel)this.DataContext;
viewModel.FtoEButtonToggled();
get
{
if (donotuse_NotationPressed == null)
{
donotuse_NotationPressed = DelegateCommandUtils.MakeDelegateCommand(this,
(that, param) =>
{
that.OnNotationButtonPressed(param);
});
}
return donotuse_NotationPressed;
}
}
private System.Windows.Input.ICommand donotuse_NotationPressed;

private void OnNotationButtonPressed(object commandParameter)
{
string buttonId = (string)commandParameter;

AutoButton.Visibility = Visibility.Collapsed;
SciButton.Visibility = Visibility.Collapsed;
EngButton.Visibility = Visibility.Collapsed;

if (buttonId == "0")
{
Model.FtoEButtonToggled();
SciButton.Visibility = Visibility.Visible;
SciButton.Focus(FocusState.Programmatic);
}
else if (buttonId == "1")
{
Model.EngButton();
EngButton.Visibility = Visibility.Visible;
EngButton.Focus(FocusState.Programmatic);
}
else if (buttonId == "2")
{
Model.FtoEButtonToggled();
AutoButton.Visibility = Visibility.Visible;
AutoButton.Focus(FocusState.Programmatic);
}
}

private bool m_isErrorVisualState;
Expand Down
43 changes: 37 additions & 6 deletions src/CalculatorUITestFramework/ScientificOperatorsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ public enum AngleOperatorState

public enum FEButtonState
{
Normal,
Exponential
Auto,
Scientific,
Engineering
}

/// <summary>
Expand Down Expand Up @@ -78,11 +79,14 @@ public class ScientificOperatorsPanel
public WindowsElement RandButton => this.session.TryFindElementByAccessibilityId("randButton");
public WindowsElement DmsButton => this.session.TryFindElementByAccessibilityId("dmsButton");
public WindowsElement DegreesButton => this.session.TryFindElementByAccessibilityId("degreesButton");
public WindowsElement FixedToExponentialButton => this.session.TryFindElementByAccessibilityId("ftoeButton");
public WindowsElement AutoButton => this.session.TryFindElementByAccessibilityId("autoButton");
public WindowsElement SciButton => this.session.TryFindElementByAccessibilityId("sciButton");
public WindowsElement EngButton => this.session.TryFindElementByAccessibilityId("engButton");
public WindowsElement NegateButton => this.session.TryFindElementByAccessibilityId("negateButton");
public WindowsElement ShiftButton => this.session.TryFindElementByAccessibilityId("shiftButton");
public WindowsElement TrigFlyout => this.session.TryFindElementByAccessibilityId("Trigflyout");
public WindowsElement LightDismiss => this.session.TryFindElementByAccessibilityId("Light Dismiss");
private WindowsElement AutoSciEngButton => GetNumberFormatButton();
private WindowsElement DegRadGradButton => GetAngleOperatorButton();
private WindowsElement GetAngleOperatorButton()
{
Expand All @@ -103,6 +107,25 @@ private WindowsElement GetAngleOperatorButton()
throw new NotFoundException("Could not find deg, rad or grad button in page source");
}

private WindowsElement GetNumberFormatButton()
{
string source = this.session.PageSource;
if (source.Contains("autoButton"))
{
return AutoButton;
}
else if (source.Contains("sciButton"))
{
return SciButton;
}
else if (source.Contains("engButton"))
{
return EngButton;
}

throw new NotFoundException("Could not find auto, sci, or eng button in page source");
}

/// <summary>
/// Set the state of the degrees, radians and gradians buttons.
/// </summary>
Expand All @@ -122,11 +145,19 @@ public void SetAngleOperator(AngleOperatorState value)
}
}

public void ResetFEButton(FEButtonState value)
public void SetNumberFormat(FEButtonState value)
{
if (this.FixedToExponentialButton.GetAttribute("Toggle.ToggleState") != "0")
//set the desired string value for the button
string desiredId = value switch
{
FEButtonState.Auto => "autoButton",
FEButtonState.Scientific => "sciButton",
FEButtonState.Engineering => "engButton",
_ => throw new NotImplementedException()
};
while (this.AutoSciEngButton.GetAttribute("AutomationId") != desiredId)
{
FixedToExponentialButton.Click();
this.AutoSciEngButton.Click();
}
}

Expand Down
1 change: 1 addition & 0 deletions src/CalculatorUITests/CurrencyConverterFunctionalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using CalculatorUITestFramework;

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace CalculatorUITests
{
Expand Down
19 changes: 15 additions & 4 deletions src/CalculatorUITests/ScientificModeFunctionalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void TestInit()
}
CalculatorApp.EnsureCalculatorHasFocus();
page.ScientificOperators.SetAngleOperator(AngleOperatorState.Degrees);
page.ScientificOperators.ResetFEButton(FEButtonState.Normal);
page.ScientificOperators.SetNumberFormat(FEButtonState.Auto);
}

[TestCleanup]
Expand Down Expand Up @@ -161,11 +161,22 @@ public void SmokeTest_GradianAngleOperator()

[TestMethod]
[Priority(0)]
public void SmokeTest_FixedToExponential()
public void SmokeTest_ScientificFormat()
{
page.ScientificOperators.FixedToExponentialButton.Click();
page.ScientificOperators.SetNumberFormat(FEButtonState.Scientific);
page.StandardOperators.NumberPad.Input(0.123);
page.StandardOperators.EqualButton.Click();
Assert.AreEqual("0.e+0", page.CalculatorResults.GetCalculatorResultText());
Assert.AreEqual("1.23e-1", page.CalculatorResults.GetCalculatorResultText());
}

[TestMethod]
[Priority(0)]
public void SmokeTest_EngineeringFormat()
{
page.ScientificOperators.SetNumberFormat(FEButtonState.Engineering);
page.StandardOperators.NumberPad.Input(0.123);
page.StandardOperators.EqualButton.Click();
Assert.AreEqual("123.e-3", page.CalculatorResults.GetCalculatorResultText());
}
#endregion

Expand Down