mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[solver] Add a modal with equation models when adding a new equation
This commit is contained in:
@@ -11,6 +11,7 @@ DataTab = "Daten"
|
||||
DefaultSetting = "Grundeinstellungen"
|
||||
Deg = "gra"
|
||||
DisplayValues = "Werte anzeigen"
|
||||
Empty = "Leer"
|
||||
ExitExamMode1 = "Wollen Sie den Testmodus "
|
||||
ExitExamMode2 = "verlassen?"
|
||||
ForbiddenValue = "Verbotener Wert"
|
||||
|
||||
@@ -11,6 +11,7 @@ DataTab = "Data"
|
||||
DefaultSetting = "Basic settings"
|
||||
Deg = "deg"
|
||||
DisplayValues = "Display values"
|
||||
Empty = "Empty"
|
||||
ExitExamMode1 = "Exit the exam "
|
||||
ExitExamMode2 = "mode?"
|
||||
ForbiddenValue = "Forbidden value"
|
||||
|
||||
@@ -11,6 +11,7 @@ DataTab = "Datos"
|
||||
DefaultSetting = "Ajustes basicos"
|
||||
Deg = "gra"
|
||||
DisplayValues = "Visualizar los valores"
|
||||
Empty = "Vacio"
|
||||
ExitExamMode1 = "Salir del modo "
|
||||
ExitExamMode2 = "examen ?"
|
||||
ForbiddenValue = "Valor prohibido"
|
||||
|
||||
@@ -11,6 +11,7 @@ DataTab = "Donnees"
|
||||
DefaultSetting = "Reglages de base"
|
||||
Deg = "deg"
|
||||
DisplayValues = "Afficher les valeurs"
|
||||
Empty = "Vide"
|
||||
ExitExamMode1 = "Voulez-vous sortir "
|
||||
ExitExamMode2 = "du mode examen ?"
|
||||
ForbiddenValue = "Valeur interdite"
|
||||
|
||||
@@ -11,6 +11,7 @@ DataTab = "Dados"
|
||||
DefaultSetting = "Configuracoes basicas"
|
||||
Deg = "gra"
|
||||
DisplayValues = "Exibir os valores"
|
||||
Empty = "Vacuo"
|
||||
ExitExamMode1 = "Voce quer sair do modo de "
|
||||
ExitExamMode2 = "exame ?"
|
||||
ForbiddenValue = "Valor proibida"
|
||||
|
||||
@@ -3,6 +3,7 @@ snapshot_headers += apps/solver/app.h
|
||||
|
||||
app_objs += $(addprefix apps/solver/,\
|
||||
app.o\
|
||||
equation_models_parameter_controller.o\
|
||||
equation_store.o\
|
||||
list_controller.o\
|
||||
)
|
||||
|
||||
@@ -3,3 +3,4 @@ SolverAppCapital = "EQUATION"
|
||||
AddEquation = "Ajouter une équation"
|
||||
Resolve = "Résoudre"
|
||||
RequireEquation = "L'entrée doit être une équation"
|
||||
UseEquationModel = "Utiliser le modèle d'équation"
|
||||
|
||||
@@ -3,3 +3,4 @@ SolverAppCapital = "EQUATION"
|
||||
AddEquation = "Ajouter une équation"
|
||||
Resolve = "Résoudre l'équation"
|
||||
RequireEquation = "L'entrée doit être une équation"
|
||||
UseEquationModel = "Utiliser le modèle d'équation"
|
||||
|
||||
@@ -3,3 +3,4 @@ SolverAppCapital = "EQUATION"
|
||||
AddEquation = "Ajouter une équation"
|
||||
Resolve = "Résoudre"
|
||||
RequireEquation = "L'entrée doit être une équation"
|
||||
UseEquationModel = "Utiliser le modèle d'équation"
|
||||
|
||||
@@ -3,3 +3,4 @@ SolverAppCapital = "EQUATION"
|
||||
AddEquation = "Ajouter une équation"
|
||||
Resolve = "Résoudre l'équation"
|
||||
RequireEquation = "L'entrée doit être une équation"
|
||||
UseEquationModel = "Utiliser le modèle d'équation"
|
||||
|
||||
@@ -3,3 +3,4 @@ SolverAppCapital = "EQUATION"
|
||||
AddEquation = "Ajouter une équation"
|
||||
Resolve = "Résoudre"
|
||||
RequireEquation = "L'entrée doit être une équation"
|
||||
UseEquationModel = "Utiliser le modèle d'équation"
|
||||
|
||||
106
apps/solver/equation_models_parameter_controller.cpp
Normal file
106
apps/solver/equation_models_parameter_controller.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
#include "equation_models_parameter_controller.h"
|
||||
#include <assert.h>
|
||||
#include <poincare/layout_engine.h>
|
||||
#include "../i18n.h"
|
||||
|
||||
using namespace Poincare;
|
||||
|
||||
namespace Solver {
|
||||
|
||||
constexpr const char * EquationModelsParameterController::k_models[k_numberOfModels];
|
||||
|
||||
EquationModelsParameterController::EquationModelsParameterController(Responder * parentResponder, EquationStore * equationStore) :
|
||||
ViewController(parentResponder),
|
||||
m_emptyModelCell(I18n::Message::Empty, KDText::FontSize::Large),
|
||||
m_expressionLayouts{},
|
||||
m_selectableTableView(this),
|
||||
m_equationStore(equationStore)
|
||||
{
|
||||
m_selectableTableView.setMargins(0);
|
||||
m_selectableTableView.setShowsIndicators(false);
|
||||
for (int i = 0; i < k_numberOfExpressionCells; i++) {
|
||||
Poincare::Expression * e = Expression::parse(k_models[i+1]);
|
||||
m_expressionLayouts[i] = e->createLayout(Poincare::PrintFloat::Mode::Decimal, Poincare::Expression::ComplexFormat::Cartesian);
|
||||
delete e;
|
||||
m_modelCells[i].setExpressionLayout(m_expressionLayouts[i]);
|
||||
}
|
||||
}
|
||||
|
||||
EquationModelsParameterController::~EquationModelsParameterController() {
|
||||
for (int i = 0; i < k_numberOfExpressionCells; i++) {
|
||||
if (m_expressionLayouts[i]) {
|
||||
delete m_expressionLayouts[i];
|
||||
m_expressionLayouts[i] = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const char * EquationModelsParameterController::title() {
|
||||
return I18n::translate(I18n::Message::UseEquationModel);
|
||||
}
|
||||
|
||||
View * EquationModelsParameterController::view() {
|
||||
return &m_selectableTableView;
|
||||
}
|
||||
|
||||
void EquationModelsParameterController::viewWillAppear() {
|
||||
ViewController::viewWillAppear();
|
||||
selectCellAtLocation(0, 0);
|
||||
}
|
||||
|
||||
void EquationModelsParameterController::didBecomeFirstResponder() {
|
||||
app()->setFirstResponder(&m_selectableTableView);
|
||||
}
|
||||
|
||||
bool EquationModelsParameterController::handleEvent(Ion::Events::Event event) {
|
||||
if (event == Ion::Events::OK || event == Ion::Events::EXE) {
|
||||
Equation * newEquation = static_cast<Equation *>(m_equationStore->addEmptyModel());
|
||||
newEquation->setContent(k_models[selectedRow()]);
|
||||
app()->dismissModalViewController();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int EquationModelsParameterController::numberOfRows() {
|
||||
return k_numberOfExpressionCells+1;
|
||||
};
|
||||
|
||||
KDCoordinate EquationModelsParameterController::rowHeight(int j) {
|
||||
return Metric::ToolboxRowHeight;
|
||||
}
|
||||
|
||||
KDCoordinate EquationModelsParameterController::cumulatedHeightFromIndex(int j) {
|
||||
return rowHeight(0) * j;
|
||||
}
|
||||
|
||||
int EquationModelsParameterController::indexFromCumulatedHeight(KDCoordinate offsetY) {
|
||||
KDCoordinate height = rowHeight(0);
|
||||
if (height == 0) {
|
||||
return 0;
|
||||
}
|
||||
return (offsetY - 1) / height;
|
||||
}
|
||||
|
||||
HighlightCell * EquationModelsParameterController::reusableCell(int index, int type) {
|
||||
if (type == 0) {
|
||||
return &m_emptyModelCell;
|
||||
}
|
||||
return &m_modelCells[index];
|
||||
}
|
||||
|
||||
int EquationModelsParameterController::reusableCellCount(int type) {
|
||||
if (type == 0) {
|
||||
return 1;
|
||||
}
|
||||
return k_numberOfExpressionCells;
|
||||
}
|
||||
|
||||
int EquationModelsParameterController::typeAtLocation(int i, int j) {
|
||||
if (i == 0 && j == 0) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
46
apps/solver/equation_models_parameter_controller.h
Normal file
46
apps/solver/equation_models_parameter_controller.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef SOLVER_EQUATION_MODELS_PARAMETER_CONTROLLER_H
|
||||
#define SOLVER_EQUATION_MODELS_PARAMETER_CONTROLLER_H
|
||||
|
||||
#include <escher.h>
|
||||
#include "equation_store.h"
|
||||
|
||||
namespace Solver {
|
||||
|
||||
|
||||
class EquationModelsParameterController : public ViewController, public ListViewDataSource, public SelectableTableViewDataSource {
|
||||
public:
|
||||
EquationModelsParameterController(Responder * parentResponder, EquationStore * equationStore);
|
||||
~EquationModelsParameterController();
|
||||
EquationModelsParameterController(const EquationModelsParameterController& other) = delete;
|
||||
EquationModelsParameterController(EquationModelsParameterController&& other) = delete;
|
||||
EquationModelsParameterController& operator=(const EquationModelsParameterController& other) = delete;
|
||||
EquationModelsParameterController& operator=(EquationModelsParameterController&& other) = delete;
|
||||
const char * title() override;
|
||||
View * view() override;
|
||||
void viewWillAppear() override;
|
||||
void didBecomeFirstResponder() override;
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
int numberOfRows() override;
|
||||
KDCoordinate rowHeight(int j) override;
|
||||
KDCoordinate cumulatedHeightFromIndex(int j) override;
|
||||
int indexFromCumulatedHeight(KDCoordinate offsetY) override;
|
||||
HighlightCell * reusableCell(int index, int type) override;
|
||||
int reusableCellCount(int type) override;
|
||||
int typeAtLocation(int i, int j) override;
|
||||
private:
|
||||
constexpr static int k_numberOfModels = 6;
|
||||
static constexpr const char * k_models[k_numberOfModels] = {
|
||||
"", "x+y=0", "x^2+x+1=0", "x+y+z=0", "x^3+x^2+x+1=0", "x+y+z+t=0"
|
||||
};
|
||||
StackViewController * stackController() const;
|
||||
constexpr static int k_numberOfExpressionCells = k_numberOfModels-1;
|
||||
MessageTableCell m_emptyModelCell;
|
||||
ExpressionTableCell m_modelCells[k_numberOfExpressionCells];
|
||||
Poincare::ExpressionLayout * m_expressionLayouts[k_numberOfExpressionCells];
|
||||
SelectableTableView m_selectableTableView;
|
||||
EquationStore * m_equationStore;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -15,7 +15,9 @@ ListController::ListController(Responder * parentResponder, EquationStore * equa
|
||||
StackViewController * stackController = list->stackController();
|
||||
// TODO
|
||||
//stackController->push(list->solutionPage ??)
|
||||
}, this), KDText::FontSize::Small, Palette::PurpleBright)
|
||||
}, this), KDText::FontSize::Small, Palette::PurpleBright),
|
||||
m_modelsParameterController(this, equationStore),
|
||||
m_modelsStackController(nullptr, &m_modelsParameterController, KDColorWhite, Palette::PurpleDark, Palette::PurpleDark)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -140,6 +142,10 @@ bool ListController::expressionLayoutFieldDidReceiveEvent(ExpressionLayoutField
|
||||
return false;
|
||||
}
|
||||
|
||||
void ListController::addEmptyModel() {
|
||||
app()->displayModalViewController(&m_modelsStackController, 0.f, 0.f, Metric::CommonTopMargin, Metric::CommonRightMargin, 0, Metric::CommonLeftMargin);
|
||||
}
|
||||
|
||||
View * ListController::loadView() {
|
||||
for (int i = 0; i < k_maxNumberOfRows; i++) {
|
||||
m_expressionCells[i] = new ModelExpressionCell();
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "../shared/expression_layout_field_delegate.h"
|
||||
#include "../shared/text_field_delegate.h"
|
||||
#include "equation_store.h"
|
||||
#include "equation_models_parameter_controller.h"
|
||||
#include "../i18n.h"
|
||||
|
||||
namespace Solver {
|
||||
@@ -45,6 +46,7 @@ public:
|
||||
bool expressionLayoutFieldDidReceiveEvent(ExpressionLayoutField * expressionLayoutField, Ion::Events::Event event) override;
|
||||
private:
|
||||
constexpr static int k_maxNumberOfRows = 5; // Ion::Display::Height / Metric::StoreRowHeight = 4.8;
|
||||
void addEmptyModel() override;
|
||||
View * loadView() override;
|
||||
void unloadView(View * view) override;
|
||||
Shared::ExpressionModelStore * modelStore() override { return m_equationStore; }
|
||||
@@ -55,6 +57,8 @@ private:
|
||||
EquationStore * m_equationStore;
|
||||
Shared::ModelExpressionCell * m_expressionCells[k_maxNumberOfRows];
|
||||
Button m_resolveButton;
|
||||
EquationModelsParameterController m_modelsParameterController;
|
||||
StackViewController m_modelsStackController;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -2,4 +2,3 @@ Variables = "Variablen"
|
||||
Number = "Zahlen"
|
||||
Matrix = "Matrizen"
|
||||
List = "Listen"
|
||||
Empty = "Leer"
|
||||
|
||||
@@ -2,4 +2,3 @@ Variables = "Variables"
|
||||
Number = "Numbers"
|
||||
Matrix = "Matrices"
|
||||
List = "Lists"
|
||||
Empty = "Empty"
|
||||
|
||||
@@ -2,4 +2,3 @@ Variables = "Variables"
|
||||
Number = "Numeros"
|
||||
Matrix = "Matrices"
|
||||
List = "Listas"
|
||||
Empty = "Vacio"
|
||||
|
||||
@@ -2,4 +2,3 @@ Variables = "Variables"
|
||||
Number = "Nombres"
|
||||
Matrix = "Matrices"
|
||||
List = "Listes"
|
||||
Empty = "Vide"
|
||||
|
||||
@@ -2,4 +2,3 @@ Variables = "Variaveis"
|
||||
Number = "Numeros"
|
||||
Matrix = "Matrizes"
|
||||
List = "Listas"
|
||||
Empty = "Vacuo"
|
||||
|
||||
Reference in New Issue
Block a user