Numworks Epsilon  1.4.1
Graphing Calculator Operating System
math_toolbox.cpp
Go to the documentation of this file.
1 #include "math_toolbox.h"
3 #include <assert.h>
4 #include <string.h>
5 
6 /* TODO: find a shorter way to initialize tree models
7  * We create one model tree: each node keeps the label of the row it refers to
8  * and the text which would be edited by clicking on the row. When the node is a
9  * subtree, the edited text is set at I18n::Message::Default. */
10 
12  ToolboxMessageTree(I18n::Message::DiffCommandWithArg, I18n::Message::DerivateNumber, I18n::Message::DiffCommandWithArg),
13  ToolboxMessageTree(I18n::Message::IntCommandWithArg, I18n::Message::Integral, I18n::Message::IntCommandWithArg),
14  ToolboxMessageTree(I18n::Message::SumCommandWithArg, I18n::Message::Sum, I18n::Message::SumCommandWithArg),
15  ToolboxMessageTree(I18n::Message::ProductCommandWithArg, I18n::Message::Product, I18n::Message::ProductCommandWithArg)};
16 
18  ToolboxMessageTree(I18n::Message::AbsCommandWithArg,I18n::Message::ComplexAbsoluteValue, I18n::Message::AbsCommandWithArg),
19  ToolboxMessageTree(I18n::Message::ArgCommandWithArg, I18n::Message::Agument, I18n::Message::ArgCommandWithArg),
20  ToolboxMessageTree(I18n::Message::ReCommandWithArg, I18n::Message::RealPart, I18n::Message::ReCommandWithArg),
21  ToolboxMessageTree(I18n::Message::ImCommandWithArg, I18n::Message::ImaginaryPart, I18n::Message::ImCommandWithArg),
22  ToolboxMessageTree(I18n::Message::ConjCommandWithArg, I18n::Message::Conjugate, I18n::Message::ConjCommandWithArg)};
23 
25  ToolboxMessageTree(I18n::Message::BinomialCommandWithArg, I18n::Message::Combination, I18n::Message::BinomialCommandWithArg),
26  ToolboxMessageTree(I18n::Message::PermuteCommandWithArg, I18n::Message::Permutation, I18n::Message::PermuteCommandWithArg)};
27 
29  ToolboxMessageTree(I18n::Message::GcdCommandWithArg, I18n::Message::GreatCommonDivisor, I18n::Message::GcdCommandWithArg),
30  ToolboxMessageTree(I18n::Message::LcmCommandWithArg, I18n::Message::LeastCommonMultiple, I18n::Message::LcmCommandWithArg),
31  ToolboxMessageTree(I18n::Message::FactorCommandWithArg, I18n::Message::PrimeFactorDecomposition, I18n::Message::FactorCommandWithArg),
32  ToolboxMessageTree(I18n::Message::RemCommandWithArg, I18n::Message::Remainder, I18n::Message::RemCommandWithArg),
33  ToolboxMessageTree(I18n::Message::QuoCommandWithArg, I18n::Message::Quotient, I18n::Message::QuoCommandWithArg)};
34 
35 #if MATRICES_ARE_DEFINED
37  ToolboxMessageTree(I18n::Message::InverseCommandWithArg, I18n::Message::Inverse, I18n::Message::InverseCommandWithArg),
38  ToolboxMessageTree(I18n::Message::DeterminantCommandWithArg, I18n::Message::Determinant, I18n::Message::DeterminantCommandWithArg),
39  ToolboxMessageTree(I18n::Message::TransposeCommandWithArg, I18n::Message::Transpose, I18n::Message::TransposeCommandWithArg),
40  ToolboxMessageTree(I18n::Message::TraceCommandWithArg, I18n::Message::Trace, I18n::Message::TraceCommandWithArg),
41  ToolboxMessageTree(I18n::Message::DimensionCommandWithArg, I18n::Message::Dimension, I18n::Message::DimensionCommandWithArg)};
42 #endif
43 
44 #if LIST_ARE_DEFINED
45 const ToolboxMessageTree listesChildren[5] = {
46  ToolboxMessageTree(I18n::Message::SortCommandWithArg, I18n::Message::Sort, I18n::Message::SortCommandWithArg),
47  ToolboxMessageTree(I18n::Message::InvSortCommandWithArg, I18n::Message::InvSort, I18n::Message::InvSortCommandWithArg),
48  ToolboxMessageTree(I18n::Message::MaxCommandWithArg, I18n::Message::Maximum, I18n::Message::MaxCommandWithArg),
49  ToolboxMessageTree(I18n::Message::MinCommandWithArg, I18n::Message::Minimum, I18n::Message::MinCommandWithArg),
50  ToolboxMessageTree(I18n::Message::DimensionCommandWithArg, I18n::Message::Dimension, I18n::Message::DimensionCommandWithArg)};
51 #endif
52 
54  ToolboxMessageTree(I18n::Message::RandomCommandWithArg, I18n::Message::RandomFloat, I18n::Message::RandomCommandWithArg),
55  ToolboxMessageTree(I18n::Message::RandintCommandWithArg, I18n::Message::RandomInteger, I18n::Message::RandintCommandWithArg),
56  ToolboxMessageTree(I18n::Message::FloorCommandWithArg, I18n::Message::Floor, I18n::Message::FloorCommandWithArg),
57  ToolboxMessageTree(I18n::Message::FracCommandWithArg, I18n::Message::FracPart, I18n::Message::FracCommandWithArg),
58  ToolboxMessageTree(I18n::Message::CeilCommandWithArg, I18n::Message::Ceiling, I18n::Message::CeilCommandWithArg),
59  ToolboxMessageTree(I18n::Message::RoundCommandWithArg, I18n::Message::Rounding, I18n::Message::RoundCommandWithArg)};
60 
62  ToolboxMessageTree(I18n::Message::CoshCommandWithArg, I18n::Message::HyperbolicCosine, I18n::Message::CoshCommandWithArg),
63  ToolboxMessageTree(I18n::Message::SinhCommandWithArg, I18n::Message::HyperbolicSine, I18n::Message::SinhCommandWithArg),
64  ToolboxMessageTree(I18n::Message::TanhCommandWithArg, I18n::Message::HyperbolicTangent, I18n::Message::TanhCommandWithArg),
65  ToolboxMessageTree(I18n::Message::AcoshCommandWithArg, I18n::Message::InverseHyperbolicCosine, I18n::Message::AcoshCommandWithArg),
66  ToolboxMessageTree(I18n::Message::AsinhCommandWithArg, I18n::Message::InverseHyperbolicSine, I18n::Message::AsinhCommandWithArg),
67  ToolboxMessageTree(I18n::Message::AtanhCommandWithArg, I18n::Message::InverseHyperbolicTangent, I18n::Message::AtanhCommandWithArg)};
68 
70  ToolboxMessageTree(I18n::Message::Prediction95CommandWithArg, I18n::Message::Prediction95, I18n::Message::Prediction95CommandWithArg),
71  ToolboxMessageTree(I18n::Message::PredictionCommandWithArg, I18n::Message::Prediction, I18n::Message::PredictionCommandWithArg),
72  ToolboxMessageTree(I18n::Message::ConfidenceCommandWithArg, I18n::Message::Confidence, I18n::Message::ConfidenceCommandWithArg)};
73 
74 #if LIST_ARE_DEFINED
75 const ToolboxMessageTree menu[12] = {ToolboxMessageTree(I18n::Message::AbsCommandWithArg, I18n::Message::AbsoluteValue, I18n::Message::AbsCommandWithArg),
76 #elif MATRICES_ARE_DEFINED
77 const ToolboxMessageTree menu[11] = {ToolboxMessageTree(I18n::Message::AbsCommandWithArg, I18n::Message::AbsoluteValue, I18n::Message::AbsCommandWithArg),
78 #else
79 const ToolboxMessageTree menu[10] = {ToolboxMessageTree(I18n::Message::AbsCommandWithArg, I18n::Message::AbsoluteValue, I18n::Message::AbsCommandWithArg),
80 #endif
81  ToolboxMessageTree(I18n::Message::RootCommandWithArg, I18n::Message::NthRoot, I18n::Message::RootCommandWithArg),
82  ToolboxMessageTree(I18n::Message::LogCommandWithArg, I18n::Message::BasedLogarithm, I18n::Message::LogCommandWithArg),
83  ToolboxMessageTree(I18n::Message::Calculation, I18n::Message::Default, I18n::Message::Default, calculChildren, 4),
84  ToolboxMessageTree(I18n::Message::ComplexNumber, I18n::Message::Default, I18n::Message::Default, complexChildren, 5),
85  ToolboxMessageTree(I18n::Message::Probability, I18n::Message::Default, I18n::Message::Default, probabilityChildren, 2),
86  ToolboxMessageTree(I18n::Message::Arithmetic, I18n::Message::Default, I18n::Message::Default, arithmeticChildren, 5),
87 #if MATRICES_ARE_DEFINED
88  ToolboxMessageTree(I18n::Message::Matrices, I18n::Message::Default, I18n::Message::Default, matricesChildren, 5),
89 #endif
90 #if LIST_ARE_DEFINED
91  ToolboxMessageTree(I18n::Message::Lists, I18n::Message::Default, I18n::Message::Default, listesChildren, 5),
92 #endif
93  ToolboxMessageTree(I18n::Message::RandomAndApproximation, I18n::Message::Default, I18n::Message::Default, randomAndApproximationChildren, 6),
94  ToolboxMessageTree(I18n::Message::HyperbolicTrigonometry, I18n::Message::Default, I18n::Message::Default, trigonometryChildren, 6),
95  ToolboxMessageTree(I18n::Message::Fluctuation, I18n::Message::Default, I18n::Message::Default, predictionChildren, 3)};
96 #if LIST_ARE_DEFINED
97 const ToolboxMessageTree toolboxModel = ToolboxMessageTree(I18n::Message::Toolbox, I18n::Message::Default, I18n::Message::Default, menu, 12);
98 #elif MATRICES_ARE_DEFINED
99 const ToolboxMessageTree toolboxModel = ToolboxMessageTree(I18n::Message::Toolbox, I18n::Message::Default, I18n::Message::Default, menu, 11);
100 #else
101 const ToolboxMessageTree toolboxModel = ToolboxMessageTree(I18n::Message::Toolbox, I18n::Message::Default, I18n::Message::Default, menu, 10);
102 #endif
103 
104 MathToolbox::MathToolbox() : Toolbox(nullptr, I18n::translate(rootModel()->label()))
105 {
106 }
107 
109  return (TextField *)Toolbox::sender();
110 }
111 
112 bool MathToolbox::selectLeaf(ToolboxMessageTree * selectedMessageTree) {
114  ToolboxMessageTree * messageTree = selectedMessageTree;
115  const char * editedText = I18n::translate(messageTree->insertedText());
116  char strippedEditedText[strlen(editedText)];
117  Shared::ToolboxHelpers::TextToInsertForCommandMessage(messageTree->insertedText(), strippedEditedText);
118  sender()->handleEventWithText(strippedEditedText);
120  return true;
121 }
122 
124  return &toolboxModel;
125 }
126 
128  assert(index >= 0 && index < k_maxNumberOfDisplayedRows);
129  return &m_leafCells[index];
130 }
131 
133  assert(index >= 0 && index < k_maxNumberOfDisplayedRows);
134  return &m_nodeCells[index];
135 }
136 
139 }
const ToolboxMessageTree probabilityChildren[2]
const ToolboxMessageTree arithmeticChildren[5]
Definition: i18n.h:6
#define assert(e)
Definition: assert.h:9
const ToolboxMessageTree toolboxModel
const ToolboxMessageTree trigonometryChildren[6]
SelectableTableView m_selectableTableView
Definition: toolbox.h:81
const ToolboxMessageTree menu[11]
const ToolboxMessageTree calculChildren[4]
const ToolboxMessageTree * rootModel() override
static constexpr int k_maxNumberOfDisplayedRows
Definition: math_toolbox.h:18
enum Message uint16_t enum Language uint16_t const char * translate(Message m, Language l=(Language) 0)
Definition: i18n.cpp:5
void TextToInsertForCommandMessage(I18n::Message message, char *buffer)
size_t strlen(const char *s)
Definition: strlen.c:3
bool selectLeaf(ToolboxMessageTree *selectedMessageTree) override
virtual Responder * sender()
Definition: toolbox.cpp:238
MessageTableCellWithMessage * leafCellAtIndex(int index) override
int maxNumberOfDisplayedRows() override
I18n::Message insertedText() const
TextField * sender() override
const ToolboxMessageTree complexChildren[5]
bool handleEventWithText(const char *text, bool indenting=false) override
Definition: text_field.cpp:303
const ToolboxMessageTree matricesChildren[5]
const ToolboxMessageTree randomAndApproximationChildren[6]
constexpr Event Toolbox
Definition: events.h:75
App * app()
Definition: responder.cpp:77
void dismissModalViewController()
Definition: app.cpp:93
MessageTableCellWithChevron * nodeCellAtIndex(int index) override
const ToolboxMessageTree predictionChildren[3]