Blue Brain BioExplorer
AnimationParameters.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2024, EPFL/Blue Brain Project
3  *
4  * The Blue Brain BioExplorer is a tool for scientists to extract and analyse
5  * scientific data from visualization
6  *
7  * This file is part of Blue Brain BioExplorer <https://github.com/BlueBrain/BioExplorer>
8  *
9  * This library is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU Lesser General Public License version 3.0 as published
11  * by the Free Software Foundation.
12  *
13  * This library is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #include "AnimationParameters.h"
24 
25 namespace
26 {
27 constexpr auto PARAM_ANIMATION_FRAME = "animation-frame";
28 constexpr auto PARAM_PLAY_ANIMATION = "play-animation";
29 } // namespace
30 
31 namespace core
32 {
34  : AbstractParameters("Animation")
35 {
36  _parameters.add_options()(PARAM_ANIMATION_FRAME, po::value<uint32_t>(&_current),
37  "Scene animation frame [uint]")(PARAM_PLAY_ANIMATION,
38  po::bool_switch(&_playing)->default_value(false),
39  "Start animation playback");
40 }
41 
43 {
45  CORE_INFO("Animation frame : " << _current);
46 }
47 
49 {
50  _updateValue(_current, 0u, false);
51  _updateValue(_dt, 0., false);
52  _updateValue(_numFrames, 0u, false);
53  _updateValue(_playing, false, false);
54  _updateValue(_unit, std::string(), false);
55 
56  // trigger the modified callback only once
57  if (isModified())
58  markModified();
59 }
60 
61 void AnimationParameters::setDelta(const int32_t delta)
62 {
63  if (delta == 0)
64  throw std::logic_error("Animation delta cannot be set to 0");
65  _updateValue(_delta, delta);
66 }
67 
69 {
70  if (_playing && _canUpdateFrame())
71  setFrame(getFrame() + getDelta());
72 }
73 
75 {
76  if (_canUpdateFrame())
77  setFrame(getFrame() + frames);
78 }
79 
80 bool AnimationParameters::_canUpdateFrame() const
81 {
82  return !hasIsReadyCallback() || _isReadyCallback();
83 }
84 } // namespace core
po::options_description _parameters
void setDelta(const int32_t delta)
void setFrame(uint32_t value)
void _updateValue(T &member, const T &newValue, const bool triggerCallback=true)
Definition: BaseObject.h:87
void markModified(const bool triggerCallback=true)
Definition: BaseObject.h:65
bool isModified() const
Definition: BaseObject.h:60
#define CORE_INFO(__msg)
Definition: Logs.h:33