mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-20 14:20:39 +01:00
Scenario: f(x) = 1, g(theta) = 2, go to Graph. Press ok on the polar curve, then Back, then OK on the cartesian curve : the menu is drawn as if the curve was still polar.
104 lines
3.4 KiB
C++
104 lines
3.4 KiB
C++
#include "curve_parameter_controller.h"
|
|
#include "graph_controller.h"
|
|
#include "../app.h"
|
|
#include <apps/i18n.h>
|
|
#include <assert.h>
|
|
|
|
using namespace Shared;
|
|
|
|
namespace Graph {
|
|
|
|
CurveParameterController::CurveParameterController(InputEventHandlerDelegate * inputEventHandlerDelegate, InteractiveCurveViewRange * graphRange, BannerView * bannerView, CurveViewCursor * cursor, GraphView * graphView, GraphController * graphController) :
|
|
FunctionCurveParameterController(),
|
|
m_goToParameterController(this, inputEventHandlerDelegate, graphRange, cursor, I18n::Message::X),
|
|
m_graphController(graphController),
|
|
m_calculationCell(I18n::Message::Compute),
|
|
m_derivativeCell(I18n::Message::DerivateNumber),
|
|
m_calculationParameterController(this, inputEventHandlerDelegate, graphView, bannerView, graphRange, cursor)
|
|
{
|
|
}
|
|
|
|
const char * CurveParameterController::title() {
|
|
return I18n::translate(I18n::Message::PlotOptions);
|
|
}
|
|
|
|
void CurveParameterController::willDisplayCellForIndex(HighlightCell * cell, int index) {
|
|
if (cell == &m_derivativeCell) {
|
|
SwitchView * switchView = (SwitchView *)m_derivativeCell.accessoryView();
|
|
switchView->setState(m_graphController->displayDerivativeInBanner());
|
|
}
|
|
}
|
|
|
|
bool CurveParameterController::handleEvent(Ion::Events::Event event) {
|
|
int index;
|
|
if (shouldDisplayCalculationAndDerivative()) {
|
|
index = selectedRow();
|
|
} else {
|
|
assert(selectedRow() == 0);
|
|
index = 1;
|
|
}
|
|
if (event == Ion::Events::OK || event == Ion::Events::EXE || (event == Ion::Events::Right && (index == 0 || index == 1))) {
|
|
switch (index) {
|
|
case 0:
|
|
{
|
|
m_calculationParameterController.setRecord(m_record);
|
|
StackViewController * stack = (StackViewController *)parentResponder();
|
|
stack->push(&m_calculationParameterController);
|
|
return true;
|
|
}
|
|
case 1:
|
|
return handleGotoSelection();
|
|
case 2:
|
|
{
|
|
m_graphController->setDisplayDerivativeInBanner(!m_graphController->displayDerivativeInBanner());
|
|
m_selectableTableView.reloadData();
|
|
return true;
|
|
}
|
|
default:
|
|
assert(false);
|
|
return false;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
int CurveParameterController::numberOfRows() {
|
|
return reusableCellCount();
|
|
};
|
|
|
|
HighlightCell * CurveParameterController::reusableCell(int index) {
|
|
assert(0 <= index && index < reusableCellCount());
|
|
HighlightCell * cells[] = {&m_calculationCell, &m_goToCell, &m_derivativeCell};
|
|
return cells[cellIndex(index)];
|
|
}
|
|
|
|
int CurveParameterController::reusableCellCount() {
|
|
return 1 + (shouldDisplayCalculationAndDerivative() ? 2 : 0);
|
|
}
|
|
|
|
void CurveParameterController::viewDidDisappear() {
|
|
/* Deselect the table properly because it needs to be relayouted the next time
|
|
* it appears: the number of rows might change according to the plot type. */
|
|
m_selectableTableView.deselectTable(false);
|
|
m_selectableTableView.setFrame(KDRectZero);
|
|
}
|
|
|
|
bool CurveParameterController::shouldDisplayCalculationAndDerivative() const {
|
|
Shared::ExpiringPointer<CartesianFunction> f = App::app()->functionStore()->modelForRecord(m_record);
|
|
return f->plotType() == CartesianFunction::PlotType::Cartesian;
|
|
}
|
|
|
|
int CurveParameterController::cellIndex(int visibleCellIndex) const {
|
|
if (shouldDisplayCalculationAndDerivative()) {
|
|
return visibleCellIndex;
|
|
}
|
|
assert(visibleCellIndex == 0);
|
|
return 1;
|
|
}
|
|
|
|
FunctionGoToParameterController * CurveParameterController::goToParameterController() {
|
|
return &m_goToParameterController;
|
|
}
|
|
|
|
}
|