From a7beccb6ca9b3ae8a40333607daa9f049915044f Mon Sep 17 00:00:00 2001 From: Stephanie Anderl <46726333+sanderl@users.noreply.github.com> Date: Thu, 6 Aug 2020 14:42:39 -0700 Subject: [PATCH] Updated the CanFunctionAnalysisBePerformed api to use the updated one with variableIsNotX error handling. Updated the UI to reflect the new descriptive error case to show an informative error. --- .../GraphingCalculator/EquationViewModel.cpp | 4 ++++ src/CalcViewModel/GraphingCalculatorEnums.h | 3 ++- src/Calculator/Resources/en-US/Resources.resw | 4 ++++ src/GraphControl/Control/Grapher.cpp | 11 ++++++++--- src/GraphingInterfaces/IGraphAnalyzer.h | 4 ++-- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/CalcViewModel/GraphingCalculator/EquationViewModel.cpp b/src/CalcViewModel/GraphingCalculator/EquationViewModel.cpp index 666f55ec..50592aa4 100644 --- a/src/CalcViewModel/GraphingCalculator/EquationViewModel.cpp +++ b/src/CalcViewModel/GraphingCalculator/EquationViewModel.cpp @@ -63,6 +63,10 @@ namespace CalculatorApp::ViewModel { AnalysisErrorString = m_resourceLoader->GetString(L"KGFAnalysisNotSupported"); } + else if (graphEquation->AnalysisError == static_cast(AnalysisErrorType::VariableIsNotX)) + { + AnalysisErrorString = m_resourceLoader->GetString(L"KGFVariableIsNotX"); + } return; } diff --git a/src/CalcViewModel/GraphingCalculatorEnums.h b/src/CalcViewModel/GraphingCalculatorEnums.h index 5cf136a5..8093f4a6 100644 --- a/src/CalcViewModel/GraphingCalculatorEnums.h +++ b/src/CalcViewModel/GraphingCalculatorEnums.h @@ -23,6 +23,7 @@ namespace CalculatorApp { NoError, AnalysisCouldNotBePerformed, - AnalysisNotSupported + AnalysisNotSupported, + VariableIsNotX }; } diff --git a/src/Calculator/Resources/en-US/Resources.resw b/src/Calculator/Resources/en-US/Resources.resw index 296f790c..349da060 100644 --- a/src/Calculator/Resources/en-US/Resources.resw +++ b/src/Calculator/Resources/en-US/Resources.resw @@ -4070,6 +4070,10 @@ Analysis is not supported for this function. Error displayed when graph analysis is not supported or had an error. + + + Analysis is only supported for functions in the f(x) format. Example: y=x + Error displayed when graph analysis detects the function format is not f(x). Maxima diff --git a/src/GraphControl/Control/Grapher.cpp b/src/GraphControl/Control/Grapher.cpp index 2c75e207..ee132953 100644 --- a/src/GraphControl/Control/Grapher.cpp +++ b/src/GraphControl/Control/Grapher.cpp @@ -254,17 +254,22 @@ namespace GraphControl vector equationVector; equationVector.push_back(equation); UpdateGraphOptions(graph->GetOptions(), equationVector); - - if (analyzer->CanFunctionAnalysisBePerformed()) + bool variableIsNotX; + if (analyzer->CanFunctionAnalysisBePerformed(variableIsNotX)) { if (S_OK == analyzer->PerformFunctionAnalysis( - (Graphing::Analyzer::NativeAnalysisType)Graphing::Analyzer::PerformAnalysisType::PerformAnalysisType_All)) + (Graphing::Analyzer::NativeAnalysisType)Graphing::Analyzer::PerformAnalysisType::PerformAnalysisType_All) + && !variableIsNotX) { Graphing::IGraphFunctionAnalysisData functionAnalysisData = m_solver->Analyze(analyzer.get()); return KeyGraphFeaturesInfo::Create(functionAnalysisData); } } + else if (variableIsNotX) + { + return KeyGraphFeaturesInfo::Create(CalculatorApp::AnalysisErrorType::VariableIsNotX); + } else { return KeyGraphFeaturesInfo::Create(CalculatorApp::AnalysisErrorType::AnalysisNotSupported); diff --git a/src/GraphingInterfaces/IGraphAnalyzer.h b/src/GraphingInterfaces/IGraphAnalyzer.h index 4bd962c4..5754080b 100644 --- a/src/GraphingInterfaces/IGraphAnalyzer.h +++ b/src/GraphingInterfaces/IGraphAnalyzer.h @@ -16,9 +16,9 @@ namespace Graphing::Analyzer struct IGraphAnalyzer : public NonCopyable, public NonMoveable { virtual ~IGraphAnalyzer() = default; - virtual bool CanFunctionAnalysisBePerformed() = 0; + virtual bool CanFunctionAnalysisBePerformed(bool& variableIsNotX) = 0; virtual HRESULT PerformFunctionAnalysis(NativeAnalysisType analysisType) = 0; virtual HRESULT GetAnalysisTypeCaption(const AnalysisType type, std::wstring& captionOut) const = 0; virtual HRESULT GetMessage(const GraphAnalyzerMessage msg, std::wstring& msgOut) const = 0; }; -} \ No newline at end of file +}