Numworks Epsilon  1.4.1
Graphing Calculator Operating System
graph_controller.cpp
Go to the documentation of this file.
1 #include "graph_controller.h"
2 #include "../app.h"
3 
4 using namespace Shared;
5 using namespace Poincare;
6 
7 namespace Graph {
8 
9 GraphController::GraphController(Responder * parentResponder, CartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Expression::AngleUnit * angleUnitVersion, ButtonRowController * header) :
10  FunctionGraphController(parentResponder, header, curveViewRange, &m_view, cursor, indexFunctionSelectedByCursor, modelVersion, rangeVersion, angleUnitVersion),
11  m_bannerView(),
12  m_view(functionStore, curveViewRange, m_cursor, &m_bannerView, &m_cursorView),
13  m_graphRange(curveViewRange),
14  m_curveParameterController(curveViewRange, &m_bannerView, m_cursor, &m_view, this, functionStore),
15  m_functionStore(functionStore),
16  m_displayDerivativeInBanner(false)
17 {
18  m_graphRange->setDelegate(this);
19 }
20 
22  if (m_functionStore->numberOfDefinedFunctions() == 0) {
23  return I18n::Message::NoFunction;
24  }
25  return I18n::Message::NoActivatedFunction;
26 }
27 
29  m_view.drawTangent(false);
30  FunctionGraphController::viewWillAppear();
31  selectFunctionWithCursor(indexFunctionSelectedByCursor()); // update the color of the cursor
32 }
33 
35  return m_displayDerivativeInBanner;
36 }
37 
38 void GraphController::setDisplayDerivativeInBanner(bool displayDerivative) {
39  m_displayDerivativeInBanner = displayDerivative;
40 }
41 
43  float characteristicRange = 0.0f;
45  for (int i = 0; i < functionStore()->numberOfActiveFunctions(); i++) {
46  Function * f = functionStore()->activeFunctionAtIndex(i);
47  float fRange = f->expression(myApp->localContext())->characteristicXRange(*(myApp->localContext()));
48  if (!std::isnan(fRange)) {
49  characteristicRange = fRange > characteristicRange ? fRange : characteristicRange;
50  }
51  }
52  return (characteristicRange > 0.0f ? 1.6f*characteristicRange : 10.0f);
53 }
54 
55 void GraphController::selectFunctionWithCursor(int functionIndex) {
56  FunctionGraphController::selectFunctionWithCursor(functionIndex);
58  m_cursorView.setColor(f->color());
59 }
60 
61 BannerView * GraphController::bannerView() {
62  return &m_bannerView;
63 }
64 
65 void GraphController::reloadBannerView() {
66  FunctionGraphController::reloadBannerView();
67  m_bannerView.setNumberOfSubviews(2+m_displayDerivativeInBanner);
68  if (m_functionStore->numberOfActiveFunctions() == 0 || !m_displayDerivativeInBanner) {
69  return;
70  }
71  CartesianFunction * f = m_functionStore->activeFunctionAtIndex(indexFunctionSelectedByCursor());
74 }
75 
76 bool GraphController::moveCursorHorizontally(int direction) {
77  CartesianFunction * f = m_functionStore->activeFunctionAtIndex(indexFunctionSelectedByCursor());
80 }
81 
82 void GraphController::initCursorParameters() {
83  double x = (interactiveCurveViewRange()->xMin()+interactiveCurveViewRange()->xMax())/2.0f;
84  selectFunctionWithCursor(0);
86  int functionIndex = 0;
87  double y = 0;
88  do {
89  CartesianFunction * firstFunction = functionStore()->activeFunctionAtIndex(functionIndex++);
90  y = firstFunction->evaluateAtAbscissa(x, myApp->localContext());
91  } while (std::isnan(y) && functionIndex < functionStore()->numberOfActiveFunctions());
92  m_cursor->moveTo(x, y);
94 }
95 
96 InteractiveCurveViewRange * GraphController::interactiveCurveViewRange() {
97  return m_graphRange;
98 }
99 
100 CartesianFunctionStore * GraphController::functionStore() const {
101  return m_functionStore;
102 }
103 
104 GraphView * GraphController::functionGraphView() {
105  return &m_view;
106 }
107 
108 CurveParameterController * GraphController::curveParameterController() {
109  return &m_curveParameterController;
110 }
111 
112 }
bool displayDerivativeInBanner() const
void setColor(KDColor color)
I18n::Message emptyMessage() override
float interestingXRange() override
KDColor color() const
Definition: function.h:21
Definition: app.cpp:9
static constexpr float k_cursorBottomMarginRatio
void viewWillAppear() override
virtual Poincare::Context * localContext()
void setNumberOfSubviews(int numberOfSubviews)
Definition: banner_view.cpp:17
Poincare::Expression * expression(Poincare::Context *context) const
Definition: function.cpp:72
void drawTangent(bool tangent)
Definition: graph_view.h:16
bool privateMoveCursorHorizontally(Shared::CurveViewCursor *cursor, int direction, Shared::InteractiveCurveViewRange *range, int numberOfStepsInGradUnit, Shared::Function *function, Shared::TextFieldDelegateApp *app, float cursorTopMarginRatio, float cursorRightMarginRatio, float cursorBottomMarginRatio, float cursorLeftMarginRatio)
unsigned int uint32_t
Definition: stdint.h:6
void setDisplayDerivativeInBanner(bool displayDerivative)
#define false
Definition: stdbool.h:9
void moveTo(double x, double y)
#define isnan(x)
Definition: math.h:43
void panToMakePointVisible(float x, float y, float topMarginRatio, float rightMarginRatio, float bottomMarginRation, float leftMarginRation)
void reloadDerivativeInBannerViewForCursorOnFunction(Shared::CurveViewCursor *cursor, CartesianFunction *function, Shared::TextFieldDelegateApp *app)
virtual float evaluateAtAbscissa(float x, Poincare::Context *context) const
Definition: function.h:30
CartesianFunction * activeFunctionAtIndex(int i) override
void setDelegate(InteractiveCurveViewRangeDelegate *delegate)
App * app()
Definition: responder.cpp:77
static constexpr float k_cursorTopMarginRatio