Blame view

epsilon-master/apps/shared/function_go_to_parameter_controller.cpp 1.46 KB
6663b6c9   adorian   projet complet av...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  #include "function_go_to_parameter_controller.h"
  #include "text_field_delegate_app.h"
  #include <assert.h>
  #include <cmath>
  
  namespace Shared {
  
  FunctionGoToParameterController::FunctionGoToParameterController(Responder * parentResponder, InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor, I18n::Message symbol) :
    GoToParameterController(parentResponder, graphRange, cursor, symbol),
    m_function(nullptr)
  {
  }
  
  const char * FunctionGoToParameterController::title() {
    return I18n::translate(I18n::Message::Goto);
  }
  
  double FunctionGoToParameterController::parameterAtIndex(int index) {
    assert(index == 0);
    return m_cursor->x();
  }
  
  bool FunctionGoToParameterController::setParameterAtIndex(int parameterIndex, double f) {
    assert(parameterIndex == 0);
    TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app();
    float y = m_function->evaluateAtAbscissa(f, myApp->localContext());
    if (std::fabs(f) > k_maxDisplayableFloat || std::fabs(y) > k_maxDisplayableFloat) {
      app()->displayWarning(I18n::Message::ForbiddenValue);
      return false;
    }
    if (std::isnan(y) || std::isinf(y)) {
      app()->displayWarning(I18n::Message::ValueNotReachedByFunction);
      return false;
    }
    m_cursor->moveTo(f, y);
    m_graphRange->centerAxisAround(CurveViewRange::Axis::X, m_cursor->x());
    m_graphRange->centerAxisAround(CurveViewRange::Axis::Y, m_cursor->y());
    return true;
  }
  
  void FunctionGoToParameterController::setFunction(Function * function) {
    m_function = function;
  }
  
  }