[graph] Create a static method StorageCartesianFunctionStore::Symbol()

This commit is contained in:
Émilie Feral
2018-10-18 18:07:34 +02:00
parent 4dbd7583e0
commit 8e2a30ab8e
11 changed files with 17 additions and 14 deletions

View File

@@ -63,7 +63,7 @@ void CalculationGraphController::setRecord(Ion::Storage::Record record) {
void CalculationGraphController::reloadBannerView() {
m_bannerView->setNumberOfSubviews(2);
reloadBannerViewForCursorOnFunction(m_cursor, m_record, functionStore(), 'x');
reloadBannerViewForCursorOnFunction(m_cursor, m_record, functionStore(), StorageCartesianFunctionStore::Symbol());
}
bool CalculationGraphController::moveCursor(int direction) {

View File

@@ -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, 'x');
int numberOfChar = function->derivativeNameWithArgument(buffer, bufferSize, StorageCartesianFunctionStore::Symbol());
const char * legend = "=";
numberOfChar += strlcpy(buffer+numberOfChar, legend, bufferSize-numberOfChar);
double y = function->approximateDerivative(cursor->x(), app->localContext());

View File

@@ -40,7 +40,7 @@ Layout IntegralGraphController::createFunctionLayout(StorageFunction * function)
constexpr size_t bufferSize = SymbolAbstract::k_maxNameSize+5; // f(x)dx
char buffer[bufferSize];
const char * dx = "dx";
int numberOfChars = function->nameWithArgument(buffer, bufferSize-strlen(dx), 'x');
int numberOfChars = function->nameWithArgument(buffer, bufferSize-strlen(dx), StorageCartesianFunctionStore::Symbol());
strlcpy(buffer+numberOfChars, dx, bufferSize-numberOfChars);
return LayoutHelper::String(buffer, strlen(buffer), KFont::SmallFont);
}

View File

@@ -18,18 +18,18 @@ const char * IntersectionGraphController::title() {
void IntersectionGraphController::reloadBannerView() {
m_bannerView->setNumberOfSubviews(2);
reloadBannerViewForCursorOnFunction(m_cursor, m_record, functionStore(), 'x');
reloadBannerViewForCursorOnFunction(m_cursor, m_record, functionStore(), StorageCartesianFunctionStore::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 '='
StorageCartesianFunction * f = functionStore()->modelForRecord(m_record);
int numberOfChar = f->nameWithArgument(buffer, bufferSize-2, 'x');
int numberOfChar = f->nameWithArgument(buffer, bufferSize-2, StorageCartesianFunctionStore::Symbol());
numberOfChar += strlcpy(buffer+numberOfChar, legend, bufferSize-numberOfChar);
// keep 1 char for '=';
StorageCartesianFunction * g = functionStore()->modelForRecord(m_intersectedRecord);
numberOfChar += g->nameWithArgument(buffer, bufferSize-numberOfChar-1, 'x');
numberOfChar += g->nameWithArgument(buffer, bufferSize-numberOfChar-1, StorageCartesianFunctionStore::Symbol());
numberOfChar += strlcpy(buffer+numberOfChar, legend, bufferSize-numberOfChar);
numberOfChar += PoincareHelpers::ConvertFloatToText<double>(m_cursor->y(), buffer+numberOfChar, bufferSize-numberOfChar, Constant::MediumNumberOfSignificantDigits);
strlcpy(buffer+numberOfChar, space, bufferSize-numberOfChar);

View File

@@ -40,7 +40,7 @@ void TangentGraphController::reloadBannerView() {
return;
}
App * myApp = static_cast<App *>(app());
StorageFunctionBannerDelegate::reloadBannerViewForCursorOnFunction(m_cursor, m_record, myApp->functionStore(), 'x');
StorageFunctionBannerDelegate::reloadBannerViewForCursorOnFunction(m_cursor, m_record, myApp->functionStore(), StorageCartesianFunctionStore::Symbol());
GraphControllerHelper::reloadDerivativeInBannerViewForCursorOnFunction(m_cursor, m_record, myApp);
constexpr size_t bufferSize = FunctionBannerDelegate::k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits);
char buffer[bufferSize];

View File

@@ -11,7 +11,8 @@ namespace Graph {
class StorageCartesianFunctionStore : public Shared::StorageFunctionStore {
public:
Shared::StorageCartesianFunction * modelForRecord(Ion::Storage::Record record) const override { return static_cast<Shared::StorageCartesianFunction *>(Shared::StorageFunctionStore::modelForRecord(record)); }
char symbol() const override { return 'x'; }
static char Symbol() { return 'x'; }
char symbol() const override { return Symbol(); }
private:
Ion::Storage::Record::ErrorStatus addEmptyModel() override;
const char * modelExtension() const override { return Shared::GlobalContext::funcExtension; }

View File

@@ -18,7 +18,7 @@ StorageDerivativeParameterController::StorageDerivativeParameterController(Stora
}
const char * StorageDerivativeParameterController::title() {
functionStore()->modelForRecord(m_record)->derivativeNameWithArgument(m_pageTitle, k_maxNumberOfCharsInTitle, 'x');
functionStore()->modelForRecord(m_record)->derivativeNameWithArgument(m_pageTitle, k_maxNumberOfCharsInTitle, StorageCartesianFunctionStore::Symbol());
return m_pageTitle;
}

View File

@@ -8,7 +8,7 @@ using namespace Shared;
namespace Graph {
StorageFunctionParameterController::StorageFunctionParameterController(StorageValuesController * valuesController) :
StorageValuesFunctionParameterController('x'),
StorageValuesFunctionParameterController(StorageCartesianFunctionStore::Symbol()),
m_displayDerivativeColumn(I18n::Message::DerivativeFunctionColumn),
m_valuesController(valuesController)
{

View File

@@ -45,9 +45,9 @@ void StorageValuesController::willDisplayCellAtLocation(HighlightCell * cell, in
const size_t bufferNameSize = Shared::StorageFunction::k_maxNameWithArgumentSize + 1;
char bufferName[bufferNameSize];
if (isDerivativeColumn(i)) {
function->derivativeNameWithArgument(bufferName, bufferNameSize, 'x');
function->derivativeNameWithArgument(bufferName, bufferNameSize, StorageCartesianFunctionStore::Symbol());
} else {
function->nameWithArgument(bufferName, bufferNameSize, 'x');
function->nameWithArgument(bufferName, bufferNameSize, StorageCartesianFunctionStore::Symbol());
}
myFunctionCell->setText(bufferName);
myFunctionCell->setColor(function->color());

View File

@@ -3,6 +3,7 @@
#include "shared/poincare_helpers.h"
#include "shared/storage_function.h"
#include "shared/storage_cartesian_function.h"
#include "graph/storage_cartesian_function_store.h"
#include "constant.h"
#include <escher/metric.h>
#include <assert.h>
@@ -91,7 +92,7 @@ void VariableBoxController::willDisplayCellForIndex(HighlightCell * cell, int in
} else {
assert(m_currentPage == Page::Function);
StorageCartesianFunction f(record);
symbolLength = f.nameWithArgument(symbolName, Shared::StorageFunction::k_maxNameWithArgumentSize, 'x');
symbolLength = f.nameWithArgument(symbolName, Shared::StorageFunction::k_maxNameWithArgumentSize, Graph::StorageCartesianFunctionStore::Symbol());
}
Layout symbolLayout = LayoutHelper::String(symbolName, symbolLength);
myCell->setLayout(symbolLayout);

View File

@@ -1,5 +1,6 @@
#include "variable_box_empty_controller.h"
#include <poincare/layout_helper.h>
#include "graph/storage_cartesian_function_store.h"
#include "i18n.h"
#include <assert.h>
@@ -88,7 +89,7 @@ void VariableBoxEmptyController::setType(Type type) {
case Type::Functions:
{
message = I18n::Message::EmptyFunctionBox;
char storeFunction[] = {'3', '+', 'x', Ion::Charset::Sto, 'f', '(', 'x', ')', 0};
char storeFunction[] = {'3', '+', Graph::StorageCartesianFunctionStore::Symbol(), Ion::Charset::Sto, 'f', '(', Graph::StorageCartesianFunctionStore::Symbol(), ')', 0};
layout = LayoutHelper::String(storeFunction, sizeof(storeFunction)-1, KDText::FontSize::Small);
break;
}