- Code: Select all
#include "math_toolbox.h"
#include "./shared/toolbox_helpers.h"
#include <assert.h>
#include <string.h>
using namespace Poincare;
/* We create one model tree: each node keeps the label of the row it refers to
* and the text which would be edited by clicking on the row. When the node is a
* subtree, the edited text is set at I18n::Message::Default. */
const ToolboxMessageTree calculChildren[] = {
ToolboxMessageTree::Leaf(I18n::Message::DiffCommandWithArg, I18n::Message::DerivateNumber, false, I18n::Message::DiffCommand),
ToolboxMessageTree::Leaf(I18n::Message::IntCommandWithArg, I18n::Message::Integral, false, I18n::Message::IntCommand),
ToolboxMessageTree::Leaf(I18n::Message::LimitCommandWithArg, I18n::Message::LimitValue),
ToolboxMessageTree::Leaf(I18n::Message::PtaylCommandWithArg, I18n::Message::PtaylValue),
ToolboxMessageTree::Leaf(I18n::Message::SumCommandWithArg, I18n::Message::Sum, false, I18n::Message::SumCommand),
ToolboxMessageTree::Leaf(I18n::Message::ProductCommandWithArg, I18n::Message::Product, false, I18n::Message::ProductCommand)
};
const ToolboxMessageTree algebraChildren[] = {
ToolboxMessageTree::Leaf(I18n::Message::NormalCommandWithArg, I18n::Message::NormalValue),
ToolboxMessageTree::Leaf(I18n::Message::FactorCommandWithArg, I18n::Message::FactorValue),
ToolboxMessageTree::Leaf(I18n::Message::CfactorCommandWithArg, I18n::Message::CfactorValue),
ToolboxMessageTree::Leaf(I18n::Message::PartfracCommandWithArg, I18n::Message::PartfracDecomposition),
ToolboxMessageTree::Leaf(I18n::Message::SimplifyCommandWithArg, I18n::Message::SimplifyValue),
};
const ToolboxMessageTree solveChildren[] = {
ToolboxMessageTree::Leaf(I18n::Message::SolveCommandWithArg, I18n::Message::SolveValue),
ToolboxMessageTree::Leaf(I18n::Message::CsolveCommandWithArg, I18n::Message::CsolveValue),
// ToolboxMessageTree::Leaf(I18n::Message::LinsolveCommandWithArg, I18n::Message::LinsolveValue),
ToolboxMessageTree::Leaf(I18n::Message::DesolveCommandWithArg, I18n::Message::DesolveValue),
// ToolboxMessageTree::Leaf(I18n::Message::RsolveCommandWithArg, I18n::Message::RsolveValue),
};
const ToolboxMessageTree realChildren[] = {
ToolboxMessageTree::Leaf(I18n::Message::AbsCommandWithArg, I18n::Message::AbsoluteValue),
ToolboxMessageTree::Leaf(I18n::Message::RootCommandWithArg, I18n::Message::NthRoot),
ToolboxMessageTree::Leaf(I18n::Message::LogCommandWithArg, I18n::Message::BasedLogarithm),
};
const ToolboxMessageTree complexChildren[] = {
ToolboxMessageTree::Leaf(I18n::Message::AbsCommandWithArg,I18n::Message::ComplexAbsoluteValue),
ToolboxMessageTree::Leaf(I18n::Message::ArgCommandWithArg, I18n::Message::Agument),
ToolboxMessageTree::Leaf(I18n::Message::ReCommandWithArg, I18n::Message::RealPart),
ToolboxMessageTree::Leaf(I18n::Message::ImCommandWithArg, I18n::Message::ImaginaryPart),
ToolboxMessageTree::Leaf(I18n::Message::ConjCommandWithArg, I18n::Message::Conjugate)
};
const ToolboxMessageTree probabilityChildren[] = {
ToolboxMessageTree::Leaf(I18n::Message::BinomialCommandWithArg, I18n::Message::Combination),
ToolboxMessageTree::Leaf(I18n::Message::PermuteCommandWithArg, I18n::Message::Permutation)
};
const ToolboxMessageTree arithmeticChildren[] = {
ToolboxMessageTree::Leaf(I18n::Message::GcdCommandWithArg, I18n::Message::GreatCommonDivisor),
ToolboxMessageTree::Leaf(I18n::Message::LcmCommandWithArg, I18n::Message::LeastCommonMultiple),
ToolboxMessageTree::Leaf(I18n::Message::IfactorCommandWithArg, I18n::Message::PrimeFactorDecomposition),
ToolboxMessageTree::Leaf(I18n::Message::IegcdCommandWithArg, I18n::Message::Iegcd),
ToolboxMessageTree::Leaf(I18n::Message::RemCommandWithArg, I18n::Message::Remainder),
ToolboxMessageTree::Leaf(I18n::Message::QuoCommandWithArg, I18n::Message::Quotient)
};
#if MATRICES_ARE_DEFINED
const ToolboxMessageTree matricesChildren[] = {
ToolboxMessageTree::Leaf(I18n::Message::MatrixCommandWithArg, I18n::Message::NewMatrix, false, I18n::Message::MatrixCommand),
ToolboxMessageTree::Leaf(I18n::Message::IdentityCommandWithArg, I18n::Message::Identity),
ToolboxMessageTree::Leaf(I18n::Message::RandmatrixCommandWithArg, I18n::Message::Randmatrix),
ToolboxMessageTree::Leaf(I18n::Message::DimensionCommandWithArg, I18n::Message::Dimension),
ToolboxMessageTree::Leaf(I18n::Message::InverseCommandWithArg, I18n::Message::Inverse),
ToolboxMessageTree::Leaf(I18n::Message::MatpowCommandWithArg, I18n::Message::Matpow),
ToolboxMessageTree::Leaf(I18n::Message::DeterminantCommandWithArg, I18n::Message::Determinant),
ToolboxMessageTree::Leaf(I18n::Message::TransposeCommandWithArg, I18n::Message::Transpose),
ToolboxMessageTree::Leaf(I18n::Message::TraceCommandWithArg, I18n::Message::Trace),
ToolboxMessageTree::Leaf(I18n::Message::RrefCommandWithArg, I18n::Message::Rref),
ToolboxMessageTree::Leaf(I18n::Message::KerCommandWithArg, I18n::Message::Ker),
ToolboxMessageTree::Leaf(I18n::Message::EigenvalueCommandWithArg, I18n::Message::Eigenvalue),
ToolboxMessageTree::Leaf(I18n::Message::EigenvectorCommandWithArg, I18n::Message::Eigenvector),
};
#endif
#if LIST_ARE_DEFINED
const ToolboxMessageTree listsChildren[] = {
ToolboxMessageTree::Leaf(I18n::Message::SortCommandWithArg, I18n::Message::Sort),
ToolboxMessageTree::Leaf(I18n::Message::InvSortCommandWithArg, I18n::Message::InvSort),
ToolboxMessageTree::Leaf(I18n::Message::MaxCommandWithArg, I18n::Message::Maximum),
ToolboxMessageTree::Leaf(I18n::Message::MinCommandWithArg, I18n::Message::Minimum),
ToolboxMessageTree::Leaf(I18n::Message::DimensionCommandWithArg, I18n::Message::Dimension)
};
#endif
const ToolboxMessageTree randomAndApproximationChildren[] = {
ToolboxMessageTree::Leaf(I18n::Message::RandomCommandWithArg, I18n::Message::RandomFloat),
ToolboxMessageTree::Leaf(I18n::Message::RandintCommandWithArg, I18n::Message::RandomInteger),
ToolboxMessageTree::Leaf(I18n::Message::FloorCommandWithArg, I18n::Message::Floor),
ToolboxMessageTree::Leaf(I18n::Message::FracCommandWithArg, I18n::Message::FracPart),
ToolboxMessageTree::Leaf(I18n::Message::CeilCommandWithArg, I18n::Message::Ceiling),
ToolboxMessageTree::Leaf(I18n::Message::RoundCommandWithArg, I18n::Message::Rounding)};
const ToolboxMessageTree trigonometryChildren[] = {
ToolboxMessageTree::Leaf(I18n::Message::CoshCommandWithArg, I18n::Message::HyperbolicCosine),
ToolboxMessageTree::Leaf(I18n::Message::SinhCommandWithArg, I18n::Message::HyperbolicSine),
ToolboxMessageTree::Leaf(I18n::Message::TanhCommandWithArg, I18n::Message::HyperbolicTangent),
ToolboxMessageTree::Leaf(I18n::Message::AcoshCommandWithArg, I18n::Message::InverseHyperbolicCosine),
ToolboxMessageTree::Leaf(I18n::Message::AsinhCommandWithArg, I18n::Message::InverseHyperbolicSine),
ToolboxMessageTree::Leaf(I18n::Message::AtanhCommandWithArg, I18n::Message::InverseHyperbolicTangent)};
const ToolboxMessageTree predictionChildren[] = {
ToolboxMessageTree::Leaf(I18n::Message::Prediction95CommandWithArg, I18n::Message::Prediction95),
ToolboxMessageTree::Leaf(I18n::Message::PredictionCommandWithArg, I18n::Message::Prediction),
ToolboxMessageTree::Leaf(I18n::Message::ConfidenceCommandWithArg, I18n::Message::Confidence)};
const ToolboxMessageTree menu[] = {
ToolboxMessageTree::Node(I18n::Message::RealNumber, realChildren),
ToolboxMessageTree::Node(I18n::Message::Algebra, algebraChildren),
ToolboxMessageTree::Node(I18n::Message::Calculation, calculChildren),
//ToolboxMessageTree::Node(I18n::Message::Solve, solveChildren),
ToolboxMessageTree::Node(I18n::Message::ComplexNumber, complexChildren),
ToolboxMessageTree::Node(I18n::Message::Probability, probabilityChildren),
ToolboxMessageTree::Node(I18n::Message::Arithmetic, arithmeticChildren),
#if MATRICES_ARE_DEFINED
ToolboxMessageTree::Node(I18n::Message::Matrices, matricesChildren),
#endif
#if LIST_ARE_DEFINED
ToolboxMessageTree::Node(I18n::Message::Lists,listsChildren),
#endif
ToolboxMessageTree::Node(I18n::Message::RandomAndApproximation, randomAndApproximationChildren),
ToolboxMessageTree::Node(I18n::Message::HyperbolicTrigonometry, trigonometryChildren),
ToolboxMessageTree::Node(I18n::Message::Fluctuation, predictionChildren)};
const ToolboxMessageTree toolboxModel = ToolboxMessageTree::Node(I18n::Message::Toolbox, menu);
MathToolbox::MathToolbox() :
Toolbox(nullptr, rootModel()->label())
{
}
bool MathToolbox::selectLeaf(int selectedRow) {
ToolboxMessageTree * messageTree = (ToolboxMessageTree *)m_messageTreeModel->children(selectedRow);
m_selectableTableView.deselectTable();
// Translate the message
const char * text = I18n::translate(messageTree->insertedText());
char textToInsert[k_maxMessageSize]; // Has to be in the same scope as handleEventWithText
if (messageTree->label() == messageTree->insertedText()) {
// Remove the arguments if we kept one message for both inserted and displayed message
int maxTextToInsertLength = strlen(text) + 1;
assert(maxTextToInsertLength <= k_maxMessageSize);
Shared::ToolboxHelpers::TextToInsertForCommandText(text, textToInsert, maxTextToInsertLength, true);
text = textToInsert;
}
sender()->handleEventWithText(text);
Container::activeApp()->dismissModalViewController();
return true;
}
const ToolboxMessageTree * MathToolbox::rootModel() {
return &toolboxModel;
}
MessageTableCellWithMessage * MathToolbox::leafCellAtIndex(int index) {
assert(index >= 0 && index < k_maxNumberOfDisplayedRows);
return &m_leafCells[index];
}
MessageTableCellWithChevron* MathToolbox::nodeCellAtIndex(int index) {
assert(index >= 0 && index < k_maxNumberOfDisplayedRows);
return &m_nodeCells[index];
}
int MathToolbox::maxNumberOfDisplayedRows() {
return k_maxNumberOfDisplayedRows;
}
Et le fichier i18n partage par toutes les langues (c'est plus simple...): apps/shared_universal.i18n
- Code: Select all
A = "a"
AbsCommandWithArg = "abs(x)"
AcoshCommandWithArg = "acosh(x)"
Algebra = "Algebre"
AlmostEqual = "≈"
Alpha = "alpha"
ArgCommandWithArg = "arg(z)"
AsinhCommandWithArg = "asinh(x)"
AtanhCommandWithArg = "atanh(x)"
B = "b"
BinomialCommandWithArg = "binomial(n,k)"
BlankMessage = " "
C = "c"
CapitalAlpha = "ALPHA"
CeilCommandWithArg = "ceil(x)"
CfactorCommandWithArg = "cfactor(f(x))"
CfactorValue = "Factorisation sur C"
ConfidenceCommandWithArg = "confidence(f,n)"
ConjCommandWithArg = "conj(z)"
CoshCommandWithArg = "cosh(x)"
CsolveCommandWithArg = "csolve(f(x)=0,x)"
CsolveValue = "Resoudre equation sur C"
D = "d"
DesolveCommandWithArg = "desolve(f(t,y,y'...)=0,t,y)"
DesolveValue = "Resoudre equation diff"
DeterminantCommandWithArg = "det(M)"
DiffCommandWithArg = "diff(f(x),x,a)"
DiffCommand = "diff(\x11,x,\x11)"
DimensionCommandWithArg = "dim(M)"
DiscreteLegend = "P(X="
DiscriminantFormulaDegree2 = "Δ=b^2-4ac"
E = "e"
EigenvalueCommandWithArg = "egvl(M)"
Eigenvalue = "valeurs propres"
EigenvectorCommandWithArg = "egv(M)"
Eigenvector = "vecteurs propres"
Equal = "="
FactorCommandWithArg = "factor(f(x))"
FactorValue = "Factorisation d'un polynome"
FccId = "FCC ID"
FiniteIntegralLegend = "≤X≤"
FloorCommandWithArg = "floor(x)"
FracCommandWithArg = "frac(x)"
GcdCommandWithArg = "gcd(p,q)"
ImCommandWithArg = "im(z)"
IfactorCommandWithArg = "ifactor(f(x))"
IegcdCommandWithArg = "iegcd(a,b)"
Iegcd = "Identite de Bezout a.u+b.v=d"
IdentityCommandWithArg = "identity(n)"
IntCommand = "int(\x11,x,\x11,\x11)"
IntCommandWithArg = "int(f(x),x,a,b)"
InverseCommandWithArg = "inverse(M)"
InvSortCommandWithArg = "sort>(L)"
KerCommandWithArg = "ker(M)"
Ker = "noyau d'appli. lineaire"
Lambda = "λ"
LcmCommandWithArg = "lcm(p,q)"
LeftIntegralFirstLegend = "P(X≤"
LeftIntegralSecondLegend = ")="
LimitCommandWithArg = "limit(f(x),x,a)"
LimitValue = "limite de f(x) en x=a"
LinearRegressionFormula = " y=a·x+b "
LogCommandWithArg = "log(x,a)"
MatrixCommand = "[[\x11]]"
MatrixCommandWithArg = "[[1,2][3,4]]"
MatpowCommandWithArg = "matpow(M,n)"
Matpow = "puissance de matrice"
MaxCommandWithArg = "max(L)"
MinCommandWithArg = "min(L)"
Mu = "μ"
N = "n"
NormalCommandWithArg = "normal(f(x))"
NormalValue = "-> fraction irreductible"
P = "p"
PartfracCommandWithArg = "partfrac(f(x))"
PartfracDecomposition = "decomposition en elements simples"
PermuteCommandWithArg = "perm(n,r)"
PtaylCommandWithArg = "ptayl(f(x),x,a,n)"
PtaylValue = "Dvpt Taylor de f(x) en x=a ordre n"
Prediction95CommandWithArg = "prediction95(p,n)"
PredictionCommandWithArg = "prediction(p,n)"
ProductCommand = "product(\x11,n,\x11,\x11)"
ProductCommandWithArg = "product(f(n),n,nmin,nmax)"
QuoCommandWithArg = "iquo(p,q)"
RandintCommandWithArg = "randint(a,b)"
RandmatrixCommandWithArg = "randmatrix(n,m)"
Randmatrix = "matrice aleatoire"
RandomCommandWithArg = "random()"
RealNumber = "Reels"
ReCommandWithArg = "re(z)"
RemCommandWithArg = "irem(p,q)"
RightIntegralFirstLegend = "P("
RightIntegralSecondLegend = "≤X)="
RootCommandWithArg = "root(x,n)"
RoundCommandWithArg = "round(x,n)"
RrefCommandWithArg = "rref(M)"
Rref = "reduction forme echelonnee"
R = "r"
Shift = "shift"
Sigma = "σ"
SimplifyCommandWithArg = "simplify(f)"
SimplifyValue = "simplify expression"
SinhCommandWithArg = "sinh(x)"
Solve = "Resoudre"
SolveCommandWithArg = "solve(f(x)=0,x)"
SolveValue = "Resoudre equation"
SortCommandWithArg = "sort<(L)"
SumCommand = "sum(\x11,n,\x11,\x11)"
SumCommandWithArg = "sum(f(n),n,nmin,nmax)"
Sxy = "∑xy"
TanhCommandWithArg = "tanh(x)"
TraceCommandWithArg = "trace(M)"
TransposeCommandWithArg = "transpose(M)"
XMax = "Xmax"
XMin = "Xmin"
X = "x"
YAuto = "Y auto"
YMax = "Ymax"
YMin = "Ymin"
Y = "y"