[apps/shared] ExpressionModelHandle: specify the symbol that is turned

into Unknown X in Derived classes
This commit is contained in:
Émilie Feral
2019-02-22 14:10:59 +01:00
parent b4c8c53982
commit 178a064c29
13 changed files with 18 additions and 16 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(), StorageCartesianFunctionStore::Symbol());
reloadBannerViewForCursorOnFunction(m_cursor, m_record, functionStore(), StorageCartesianFunction::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, 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());

View File

@@ -40,7 +40,7 @@ Layout IntegralGraphController::createFunctionLayout(ExpiringPointer<StorageFunc
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), 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);
}

View File

@@ -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<StorageCartesianFunction> 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<StorageCartesianFunction> 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<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(), 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];

View File

@@ -11,8 +11,7 @@ namespace Graph {
class StorageCartesianFunctionStore : public Shared::StorageFunctionStore {
public:
Shared::ExpiringPointer<Shared::StorageCartesianFunction> modelForRecord(Ion::Storage::Record record) const { return Shared::ExpiringPointer<Shared::StorageCartesianFunction>(static_cast<Shared::StorageCartesianFunction *>(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; }

View File

@@ -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() {

View File

@@ -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)
{

View File

@@ -48,9 +48,9 @@ void StorageValuesController::willDisplayCellAtLocation(HighlightCell * cell, in
* after the isDerivativeColumn call, else it will expire. */
Shared::ExpiringPointer<StorageCartesianFunction> 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());

View File

@@ -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);

View File

@@ -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;

View File

@@ -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)

View File

@@ -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);