mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-20 22:30:30 +01:00
94 lines
3.8 KiB
C++
94 lines
3.8 KiB
C++
#include "graph_controller.h"
|
|
|
|
using namespace Shared;
|
|
using namespace Poincare;
|
|
|
|
namespace Graph {
|
|
|
|
GraphController::GraphController(Responder * parentResponder, CartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, CurveViewCursor * cursor, uint32_t * modelVersion, uint32_t * rangeVersion, Expression::AngleUnit * angleUnitVersion, ButtonRowController * header) :
|
|
FunctionGraphController(parentResponder, header, curveViewRange, &m_view, cursor, modelVersion, rangeVersion, angleUnitVersion),
|
|
m_bannerView(),
|
|
m_view(functionStore, curveViewRange, m_cursor, &m_bannerView, &m_cursorView),
|
|
m_graphRange(curveViewRange),
|
|
m_curveParameterController(curveViewRange, &m_bannerView, m_cursor),
|
|
m_functionStore(functionStore)
|
|
{
|
|
m_graphRange->setDelegate(this);
|
|
}
|
|
|
|
I18n::Message GraphController::emptyMessage() {
|
|
if (m_functionStore->numberOfDefinedFunctions() == 0) {
|
|
return I18n::Message::NoFunction;
|
|
}
|
|
return I18n::Message::NoActivatedFunction;
|
|
}
|
|
|
|
BannerView * GraphController::bannerView() {
|
|
return &m_bannerView;
|
|
}
|
|
|
|
void GraphController::reloadBannerView() {
|
|
FunctionGraphController::reloadBannerView();
|
|
if (!m_bannerView.displayDerivative()) {
|
|
return;
|
|
}
|
|
char buffer[k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
|
|
const char * legend = "00(x)=";
|
|
int legendLength = strlen(legend);
|
|
strlcpy(buffer, legend, legendLength+1);
|
|
if (m_functionStore->numberOfActiveFunctions() == 0) {
|
|
return;
|
|
}
|
|
CartesianFunction * f = m_functionStore->activeFunctionAtIndex(m_indexFunctionSelectedByCursor);
|
|
buffer[0] = f->name()[0];
|
|
buffer[1] = '\'';
|
|
TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app();
|
|
double y = f->approximateDerivative(m_cursor->x(), myApp->localContext());
|
|
Complex<double>::convertFloatToText(y, buffer + legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
|
|
m_bannerView.setLegendAtIndex(buffer, 2);
|
|
}
|
|
|
|
bool GraphController::moveCursorHorizontally(int direction) {
|
|
double xCursorPosition = m_cursor->x();
|
|
double x = direction > 0 ? xCursorPosition + m_graphRange->xGridUnit()/k_numberOfCursorStepsInGradUnit :
|
|
xCursorPosition - m_graphRange->xGridUnit()/k_numberOfCursorStepsInGradUnit;
|
|
CartesianFunction * f = m_functionStore->activeFunctionAtIndex(m_indexFunctionSelectedByCursor);
|
|
TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app();
|
|
double y = f->evaluateAtAbscissa(x, myApp->localContext());
|
|
m_cursor->moveTo(x, y);
|
|
m_graphRange->panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
|
|
return true;
|
|
}
|
|
|
|
void GraphController::initCursorParameters() {
|
|
double x = (interactiveCurveViewRange()->xMin()+interactiveCurveViewRange()->xMax())/2.0f;
|
|
m_indexFunctionSelectedByCursor = 0;
|
|
TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app();
|
|
int functionIndex = 0;
|
|
double y = 0;
|
|
do {
|
|
CartesianFunction * firstFunction = functionStore()->activeFunctionAtIndex(functionIndex++);
|
|
y = firstFunction->evaluateAtAbscissa(x, myApp->localContext());
|
|
} while (isnan(y) && functionIndex < functionStore()->numberOfActiveFunctions());
|
|
m_cursor->moveTo(x, y);
|
|
interactiveCurveViewRange()->panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
|
|
}
|
|
|
|
InteractiveCurveViewRange * GraphController::interactiveCurveViewRange() {
|
|
return m_graphRange;
|
|
}
|
|
|
|
CartesianFunctionStore * GraphController::functionStore() const {
|
|
return m_functionStore;
|
|
}
|
|
|
|
GraphView * GraphController::functionGraphView() {
|
|
return &m_view;
|
|
}
|
|
|
|
CurveParameterController * GraphController::curveParameterController() {
|
|
return &m_curveParameterController;
|
|
}
|
|
|
|
}
|