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 <cmath>
3 
4 using namespace Shared;
5 using namespace Poincare;
6 
7 namespace Sequence {
8 
9 GraphController::GraphController(Responder * parentResponder, SequenceStore * sequenceStore, CurveViewRange * graphRange, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Expression::AngleUnit * angleUnitVersion, ButtonRowController * header) :
10  FunctionGraphController(parentResponder, header, graphRange, &m_view, cursor, indexFunctionSelectedByCursor, modelVersion, rangeVersion, angleUnitVersion),
11  m_bannerView(),
12  m_view(sequenceStore, graphRange, m_cursor, &m_bannerView, &m_cursorView),
13  m_graphRange(graphRange),
14  m_curveParameterController(this, graphRange, m_cursor),
15  m_termSumController(this, &m_view, graphRange, m_cursor),
16  m_sequenceStore(sequenceStore)
17 {
18  m_graphRange->setDelegate(this);
19 }
20 
22  if (m_sequenceStore->numberOfDefinedFunctions() == 0) {
23  return I18n::Message::NoSequence;
24  }
25  return I18n::Message::NoActivatedSequence;
26 }
27 
29  return &m_termSumController;
30 }
31 
32 BannerView * GraphController::bannerView() {
33  return &m_bannerView;
34 }
35 
36 bool GraphController::handleEnter() {
37  m_termSumController.setFunction(m_sequenceStore->activeFunctionAtIndex(indexFunctionSelectedByCursor()));
38  return FunctionGraphController::handleEnter();
39 }
40 
41 bool GraphController::moveCursorHorizontally(int direction) {
42  double xCursorPosition = std::round(m_cursor->x());
43  if (direction < 0 && xCursorPosition <= 0) {
44  return false;
45  }
46  /* The cursor moves by step of at minimum 1. If the windowRange is to large
47  * compared to the resolution, the cursor takes bigger round step to cross
48  * the window in approximatively resolution steps. */
49  double step = std::ceil((interactiveCurveViewRange()->xMax()-interactiveCurveViewRange()->xMin())/m_view.resolution());
50  step = step < 1.0 ? 1.0 : step;
51  double x = direction > 0 ? xCursorPosition + step:
52  xCursorPosition - step;
53  if (x < 0.0) {
54  return false;
55  }
58  double y = s->evaluateAtAbscissa(x, myApp->localContext());
59  m_cursor->moveTo(x, y);
61  return true;
62 }
63 
64 void GraphController::initCursorParameters() {
65  double x = std::round((interactiveCurveViewRange()->xMin()+interactiveCurveViewRange()->xMax())/2.0);
68  int functionIndex = 0;
69  double y = 0;
70  do {
71  Sequence * firstFunction = m_sequenceStore->activeFunctionAtIndex(functionIndex++);
72  y = firstFunction->evaluateAtAbscissa(x, myApp->localContext());
73  } while (std::isnan(y) && functionIndex < m_sequenceStore->numberOfActiveFunctions());
74  m_cursor->moveTo(x, y);
76 }
77 
78 CurveViewRange * GraphController::interactiveCurveViewRange() {
79  return m_graphRange;
80 }
81 
82 SequenceStore * GraphController::functionStore() const {
83  return m_sequenceStore;
84 }
85 
86 GraphView * GraphController::functionGraphView() {
87  return &m_view;
88 }
89 
90 CurveParameterController * GraphController::curveParameterController() {
91  return &m_curveParameterController;
92 }
93 
94 }
I18n::Message emptyMessage() override
float resolution() const
Definition: curve_view.cpp:83
Sequence * activeFunctionAtIndex(int i) override
static constexpr float k_cursorBottomMarginRatio
virtual Poincare::Context * localContext()
unsigned int uint32_t
Definition: stdint.h:6
#define round(x)
Definition: math.h:192
#define ceil(x)
Definition: math.h:170
void moveTo(double x, double y)
#define isnan(x)
Definition: math.h:43
TermSumController * termSumController()
void panToMakePointVisible(float x, float y, float topMarginRatio, float rightMarginRatio, float bottomMarginRation, float leftMarginRation)
Definition: app.cpp:7
void setFunction(Function *function)
void setDelegate(InteractiveCurveViewRangeDelegate *delegate)
App * app()
Definition: responder.cpp:77
virtual void selectFunctionWithCursor(int functionIndex)
static constexpr float k_cursorTopMarginRatio