From 64978202b4e17fc0747a1fac371576974878ec0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Fri, 22 Feb 2019 14:10:59 +0100 Subject: [PATCH] [apps/shared] ExpressionModelHandle: specify the symbol that is turned into Unknown X in Derived classes --- apps/graph/graph/calculation_graph_controller.cpp | 2 +- apps/graph/graph/graph_controller_helper.cpp | 2 +- apps/graph/graph/integral_graph_controller.cpp | 2 +- apps/graph/graph/intersection_graph_controller.cpp | 6 +++--- apps/graph/graph/tangent_graph_controller.cpp | 2 +- apps/graph/storage_cartesian_function_store.h | 3 +-- .../values/storage_derivative_parameter_controller.cpp | 2 +- apps/graph/values/storage_function_parameter_controller.cpp | 2 +- apps/graph/values/storage_values_controller.cpp | 4 ++-- apps/shared/expression_model_handle.cpp | 4 ++-- apps/shared/expression_model_handle.h | 1 + apps/shared/storage_cartesian_function.h | 2 ++ apps/variable_box_controller.cpp | 2 +- 13 files changed, 18 insertions(+), 16 deletions(-) diff --git a/apps/graph/graph/calculation_graph_controller.cpp b/apps/graph/graph/calculation_graph_controller.cpp index 1171157df..7bb84d4a8 100644 --- a/apps/graph/graph/calculation_graph_controller.cpp +++ b/apps/graph/graph/calculation_graph_controller.cpp @@ -63,7 +63,7 @@ void CalculationGraphController::setRecord(Ion::Storage::Record record) { void CalculationGraphController::reloadBannerView() { m_bannerView->setNumberOfSubviews(2); - reloadBannerViewForCursorOnFunction(m_cursor, m_record, functionStore(), StorageCartesianFunctionStore::Symbol()); + reloadBannerViewForCursorOnFunction(m_cursor, m_record, functionStore(), StorageCartesianFunction::Symbol()); } bool CalculationGraphController::moveCursor(int direction) { diff --git a/apps/graph/graph/graph_controller_helper.cpp b/apps/graph/graph/graph_controller_helper.cpp index 41ca6250c..41135c4aa 100644 --- a/apps/graph/graph/graph_controller_helper.cpp +++ b/apps/graph/graph/graph_controller_helper.cpp @@ -23,7 +23,7 @@ void GraphControllerHelper::reloadDerivativeInBannerViewForCursorOnFunction(Shar constexpr size_t bufferSize = FunctionBannerDelegate::k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits); char buffer[bufferSize]; const char * space = " "; - int numberOfChar = function->derivativeNameWithArgument(buffer, bufferSize, StorageCartesianFunctionStore::Symbol()); + int numberOfChar = function->derivativeNameWithArgument(buffer, bufferSize, StorageCartesianFunction::Symbol()); const char * legend = "="; numberOfChar += strlcpy(buffer+numberOfChar, legend, bufferSize-numberOfChar); double y = function->approximateDerivative(cursor->x(), app->localContext()); diff --git a/apps/graph/graph/integral_graph_controller.cpp b/apps/graph/graph/integral_graph_controller.cpp index f07eac2dd..c8e948f72 100644 --- a/apps/graph/graph/integral_graph_controller.cpp +++ b/apps/graph/graph/integral_graph_controller.cpp @@ -40,7 +40,7 @@ Layout IntegralGraphController::createFunctionLayout(ExpiringPointernameWithArgument(buffer, bufferSize-strlen(dx), StorageCartesianFunctionStore::Symbol()); + int numberOfChars = function->nameWithArgument(buffer, bufferSize-strlen(dx), StorageCartesianFunction::Symbol()); strlcpy(buffer+numberOfChars, dx, bufferSize-numberOfChars); return LayoutHelper::String(buffer, strlen(buffer), KDFont::SmallFont); } diff --git a/apps/graph/graph/intersection_graph_controller.cpp b/apps/graph/graph/intersection_graph_controller.cpp index fb0a81e23..93bc35422 100644 --- a/apps/graph/graph/intersection_graph_controller.cpp +++ b/apps/graph/graph/intersection_graph_controller.cpp @@ -18,18 +18,18 @@ const char * IntersectionGraphController::title() { void IntersectionGraphController::reloadBannerView() { m_bannerView->setNumberOfSubviews(2); - reloadBannerViewForCursorOnFunction(m_cursor, m_record, functionStore(), StorageCartesianFunctionStore::Symbol()); + reloadBannerViewForCursorOnFunction(m_cursor, m_record, functionStore(), StorageCartesianFunction::Symbol()); constexpr size_t bufferSize = FunctionBannerDelegate::k_maxNumberOfCharacters+Poincare::PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits); char buffer[bufferSize]; const char * space = " "; const char * legend = "="; // 'f(x)=g(x)=', keep 2 chars for '=' ExpiringPointer f = functionStore()->modelForRecord(m_record); - int numberOfChar = f->nameWithArgument(buffer, bufferSize-2, StorageCartesianFunctionStore::Symbol()); + int numberOfChar = f->nameWithArgument(buffer, bufferSize-2, StorageCartesianFunction::Symbol()); numberOfChar += strlcpy(buffer+numberOfChar, legend, bufferSize-numberOfChar); // keep 1 char for '='; ExpiringPointer g = functionStore()->modelForRecord(m_intersectedRecord); - numberOfChar += g->nameWithArgument(buffer+numberOfChar, bufferSize-numberOfChar-1, StorageCartesianFunctionStore::Symbol()); + numberOfChar += g->nameWithArgument(buffer+numberOfChar, bufferSize-numberOfChar-1, StorageCartesianFunction::Symbol()); numberOfChar += strlcpy(buffer+numberOfChar, legend, bufferSize-numberOfChar); numberOfChar += PoincareHelpers::ConvertFloatToText(m_cursor->y(), buffer+numberOfChar, bufferSize-numberOfChar, Constant::MediumNumberOfSignificantDigits); strlcpy(buffer+numberOfChar, space, bufferSize-numberOfChar); diff --git a/apps/graph/graph/tangent_graph_controller.cpp b/apps/graph/graph/tangent_graph_controller.cpp index b3ab42e99..c66985d4a 100644 --- a/apps/graph/graph/tangent_graph_controller.cpp +++ b/apps/graph/graph/tangent_graph_controller.cpp @@ -40,7 +40,7 @@ void TangentGraphController::reloadBannerView() { return; } App * myApp = static_cast(app()); - StorageFunctionBannerDelegate::reloadBannerViewForCursorOnFunction(m_cursor, m_record, myApp->functionStore(), StorageCartesianFunctionStore::Symbol()); + StorageFunctionBannerDelegate::reloadBannerViewForCursorOnFunction(m_cursor, m_record, myApp->functionStore(), StorageCartesianFunction::Symbol()); GraphControllerHelper::reloadDerivativeInBannerViewForCursorOnFunction(m_cursor, m_record, myApp); constexpr size_t bufferSize = FunctionBannerDelegate::k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits); char buffer[bufferSize]; diff --git a/apps/graph/storage_cartesian_function_store.h b/apps/graph/storage_cartesian_function_store.h index 06a69b1ea..865faad0e 100644 --- a/apps/graph/storage_cartesian_function_store.h +++ b/apps/graph/storage_cartesian_function_store.h @@ -11,8 +11,7 @@ namespace Graph { class StorageCartesianFunctionStore : public Shared::StorageFunctionStore { public: Shared::ExpiringPointer modelForRecord(Ion::Storage::Record record) const { return Shared::ExpiringPointer(static_cast(privateModelForRecord(record))); } - static char Symbol() { return 'x'; } - char symbol() const override { return Symbol(); } + char symbol() const override { return Shared::StorageCartesianFunction::Symbol(); } private: Ion::Storage::Record::ErrorStatus addEmptyModel() override; const char * modelExtension() const override { return Shared::GlobalContext::funcExtension; } diff --git a/apps/graph/values/storage_derivative_parameter_controller.cpp b/apps/graph/values/storage_derivative_parameter_controller.cpp index a3fcf9ddd..51be4d2fc 100644 --- a/apps/graph/values/storage_derivative_parameter_controller.cpp +++ b/apps/graph/values/storage_derivative_parameter_controller.cpp @@ -18,7 +18,7 @@ StorageDerivativeParameterController::StorageDerivativeParameterController(Stora } void StorageDerivativeParameterController::viewWillAppear() { - functionStore()->modelForRecord(m_record)->derivativeNameWithArgument(m_pageTitle, k_maxNumberOfCharsInTitle, StorageCartesianFunctionStore::Symbol()); + functionStore()->modelForRecord(m_record)->derivativeNameWithArgument(m_pageTitle, k_maxNumberOfCharsInTitle, Shared::StorageCartesianFunction::Symbol()); } const char * StorageDerivativeParameterController::title() { diff --git a/apps/graph/values/storage_function_parameter_controller.cpp b/apps/graph/values/storage_function_parameter_controller.cpp index 737cafada..915344785 100644 --- a/apps/graph/values/storage_function_parameter_controller.cpp +++ b/apps/graph/values/storage_function_parameter_controller.cpp @@ -8,7 +8,7 @@ using namespace Shared; namespace Graph { StorageFunctionParameterController::StorageFunctionParameterController(StorageValuesController * valuesController) : - StorageValuesFunctionParameterController(StorageCartesianFunctionStore::Symbol()), + StorageValuesFunctionParameterController(StorageCartesianFunction::Symbol()), m_displayDerivativeColumn(I18n::Message::DerivativeFunctionColumn), m_valuesController(valuesController) { diff --git a/apps/graph/values/storage_values_controller.cpp b/apps/graph/values/storage_values_controller.cpp index 58ffdf9e1..764c990e8 100644 --- a/apps/graph/values/storage_values_controller.cpp +++ b/apps/graph/values/storage_values_controller.cpp @@ -48,9 +48,9 @@ void StorageValuesController::willDisplayCellAtLocation(HighlightCell * cell, in * after the isDerivativeColumn call, else it will expire. */ Shared::ExpiringPointer function = functionStore()->modelForRecord(recordAtColumn(i)); if (isDerivative) { - function->derivativeNameWithArgument(bufferName, bufferNameSize, StorageCartesianFunctionStore::Symbol()); + function->derivativeNameWithArgument(bufferName, bufferNameSize, StorageCartesianFunction::Symbol()); } else { - function->nameWithArgument(bufferName, bufferNameSize, StorageCartesianFunctionStore::Symbol()); + function->nameWithArgument(bufferName, bufferNameSize, StorageCartesianFunction::Symbol()); } myFunctionCell->setText(bufferName); myFunctionCell->setColor(function->color()); diff --git a/apps/shared/expression_model_handle.cpp b/apps/shared/expression_model_handle.cpp index 2faf4339e..cf8f424e3 100644 --- a/apps/shared/expression_model_handle.cpp +++ b/apps/shared/expression_model_handle.cpp @@ -90,8 +90,8 @@ Ion::Storage::Record::ErrorStatus ExpressionModelHandle::setContent(const char * if (c && *c != 0) { // Compute the expression to store, without replacing symbols expressionToStore = Expression::Parse(c); - if (!expressionToStore.isUninitialized()) { - expressionToStore = expressionToStore.replaceUnknown(Symbol::Builder('x')); //TODO Beware of non x unknowns! (for instance whe sequences are in the storage) + if (!expressionToStore.isUninitialized() && symbol() != 0) { + expressionToStore = expressionToStore.replaceUnknown(Symbol::Builder(symbol())); } } return setExpressionContent(expressionToStore); diff --git a/apps/shared/expression_model_handle.h b/apps/shared/expression_model_handle.h index 4a90f529d..b034e6ec9 100644 --- a/apps/shared/expression_model_handle.h +++ b/apps/shared/expression_model_handle.h @@ -14,6 +14,7 @@ class ExpressionModelHandle : public Ion::Storage::Record { // TODO find better name (once we remove ExpressionModel?) public: ExpressionModelHandle(Ion::Storage::Record record); + virtual char symbol() const { return 0; }; void text(char * buffer, size_t bufferSize) const; Poincare::Expression expressionReduced(Poincare::Context * context) const; Poincare::Expression expressionClone() const; diff --git a/apps/shared/storage_cartesian_function.h b/apps/shared/storage_cartesian_function.h index 9cd559934..722a07d99 100644 --- a/apps/shared/storage_cartesian_function.h +++ b/apps/shared/storage_cartesian_function.h @@ -10,6 +10,8 @@ namespace Shared { class StorageCartesianFunction : public StorageFunction { public: static void DefaultName(char buffer[], size_t bufferSize); + static char Symbol() { return 'x'; } + char symbol() const override { return Symbol(); }; static StorageCartesianFunction NewModel(Ion::Storage::Record::ErrorStatus * error, const char * baseName = nullptr); StorageCartesianFunction(Ion::Storage::Record record = Record()) : StorageFunction(record) diff --git a/apps/variable_box_controller.cpp b/apps/variable_box_controller.cpp index 24caf7a13..e27c06a23 100644 --- a/apps/variable_box_controller.cpp +++ b/apps/variable_box_controller.cpp @@ -114,7 +114,7 @@ void VariableBoxController::willDisplayCellForIndex(HighlightCell * cell, int in symbolLength = f.nameWithArgument( symbolName, Shared::StorageFunction::k_maxNameWithArgumentSize, - Graph::StorageCartesianFunctionStore::Symbol()); + Shared::StorageCartesianFunction::Symbol()); } Layout symbolLayout = LayoutHelper::String(symbolName, symbolLength); myCell->setLayout(symbolLayout);