diff --git a/apps/sequence/Makefile b/apps/sequence/Makefile index 74c4206f4..86a556221 100644 --- a/apps/sequence/Makefile +++ b/apps/sequence/Makefile @@ -6,6 +6,7 @@ app_objs += $(addprefix apps/sequence/,\ list/sequence_toolbox.o\ list/type_parameter_controller.o\ values/values_controller.o\ + local_context.o\ sequence.o\ sequence_store.o\ sequence_title_cell.o\ diff --git a/apps/sequence/app.cpp b/apps/sequence/app.cpp index aa4c7f945..d4556ec7c 100644 --- a/apps/sequence/app.cpp +++ b/apps/sequence/app.cpp @@ -8,7 +8,7 @@ namespace Sequence { App::App(Container * container, Context * context) : TextFieldDelegateApp(container, &m_inputViewController, "Suites", "SUITES", ImageStore::SequenceIcon), m_sequenceStore(SequenceStore()), - m_nContext(VariableContext('n', context)), + m_nContext(LocalContext(context)), m_listController(&m_listHeader, &m_sequenceStore, &m_listHeader), m_listHeader(HeaderViewController(nullptr, &m_listController, &m_listController)), m_listStackViewController(StackViewController(&m_tabViewController, &m_listHeader)), @@ -29,7 +29,7 @@ InputViewController * App::inputViewController() { return &m_inputViewController; } -Context * App::localContext() { +LocalContext * App::localContext() { return &m_nContext; } diff --git a/apps/sequence/app.h b/apps/sequence/app.h index df4b07b5c..adba977a7 100644 --- a/apps/sequence/app.h +++ b/apps/sequence/app.h @@ -3,6 +3,7 @@ #include #include +#include "local_context.h" #include "sequence_store.h" #include "list/list_controller.h" #include "values/values_controller.h" @@ -14,11 +15,11 @@ class App : public Shared::TextFieldDelegateApp { public: App(Container * container, Poincare::Context * context); InputViewController * inputViewController(); - Poincare::Context * localContext() override; + LocalContext * localContext() override; const char * XNT() override; private: SequenceStore m_sequenceStore; - Poincare::VariableContext m_nContext; + LocalContext m_nContext; ListController m_listController; HeaderViewController m_listHeader; StackViewController m_listStackViewController; diff --git a/apps/sequence/local_context.cpp b/apps/sequence/local_context.cpp new file mode 100644 index 000000000..de7470185 --- /dev/null +++ b/apps/sequence/local_context.cpp @@ -0,0 +1,47 @@ +#include "local_context.h" + +using namespace Poincare; + +namespace Sequence { + +LocalContext::LocalContext(Context * parentContext) : + VariableContext('n', parentContext), + m_nValue(Complex::Float(NAN)), + m_n1Value(Complex::Float(NAN)) +{ +} + +const Expression * LocalContext::expressionForSymbol(const Symbol * symbol) { + if (sequenceIndexForSymbol(symbol) == 0) { + return &m_nValue; + } + if (sequenceIndexForSymbol(symbol) == 1) { + return &m_n1Value; + } + return VariableContext::expressionForSymbol(symbol); +} + +void LocalContext::setSequenceRankValue(float f, int rank) { + if (rank == 0) { + m_nValue = Complex::Float(f); + } + if (rank == 1) { + m_n1Value = Complex::Float(f); + } +} + +char LocalContext::sequenceIndexForSymbol(const Symbol * symbol) { + if (symbol->name() == Symbol::SpecialSymbols::un || + symbol->name() == Symbol::SpecialSymbols::vn || + symbol->name() == Symbol::SpecialSymbols::wn) { + return 0; + } + if (symbol->name() == Symbol::SpecialSymbols::un1 || + symbol->name() == Symbol::SpecialSymbols::vn1 || + symbol->name() == Symbol::SpecialSymbols::wn1) { + return 1; + } + return 2; +} + +} diff --git a/apps/sequence/local_context.h b/apps/sequence/local_context.h new file mode 100644 index 000000000..7b536e900 --- /dev/null +++ b/apps/sequence/local_context.h @@ -0,0 +1,21 @@ +#ifndef SEQUENCE_LOCAL_CONTEXT_H +#define SEQUENCE_LOCAL_CONTEXT_H + +#include + +namespace Sequence { + +class LocalContext : public Poincare::VariableContext { +public: + LocalContext(Poincare::Context * parentContext); + const Poincare::Expression * expressionForSymbol(const Poincare::Symbol * symbol) override; + void setSequenceRankValue(float f, int rank); +private: + char sequenceIndexForSymbol(const Poincare::Symbol * symbol); + Poincare::Complex m_nValue; + Poincare::Complex m_n1Value; +}; + +} + +#endif \ No newline at end of file