AnimationController.h

Go to the documentation of this file.
00001 /*
00002  * The information in this file is
00003  * Copyright(c) 2007 Ball Aerospace & Technologies Corporation
00004  * and is subject to the terms and conditions of the
00005  * GNU Lesser General Public License Version 2.1
00006  * The license text is available from   
00007  * http://www.gnu.org/licenses/lgpl.html
00008  */
00009 
00010 #ifndef ANIMATIONCONTROLLER_H
00011 #define ANIMATIONCONTROLLER_H
00012 
00013 #include "ConfigurationSettings.h"
00014 #include "SessionItem.h"
00015 #include "Subject.h"
00016 #include "TypesFile.h"
00017 
00018 #include <string>
00019 #include <vector>
00020 
00021 #include <boost/rational.hpp>
00022 
00023 class Animation;
00024 
00025 /**
00026  *  Plays one or more animations synchronously.
00027  *
00028  *  An animation controller allows multiple animations to be played synchronously at a particular
00029  *  rate.  This can be particularly useful with time-based controllers.  In addition to
00030  *  the animations, the controller stores a start value, stop value, and current value.  These
00031  *  values are updated automatically when the frames in an animation change, or when an
00032  *  animation is destroyed.  The start value is defined as the minimum value across all
00033  *  frames in all animations according to the frame value type specified at the creation
00034  *  of the controller.  Similarly, the stop value is defined as the maximum value across
00035  *  all frames in all animations according to the controller's frame value type.  Animations must
00036  *  be created within the animation controller, which guarantees that the animation and the controller
00037  *  will have the same frame type.
00038  *
00039  *  When playing animations, each animation is updated at a constant frequency, specified by
00040  *  getFrequency().  This means that rate at which Animation::setCurrentFrame() is called
00041  *  does not change.  The value that is passed to the animation when the current frame is
00042  *  set can be modified by changing the interval multiplier.  This has the effect of
00043  *  speeding up or slowing down the animations.
00044  *
00045  *  The frame rate is based on the frequency and the interval multiplier.  In some cases
00046  *  the desired frame rate cannot be achieved due to limitations in the hardware.  If
00047  *  this occurs, frames will be dropped when playing through the animations to preserve the
00048  *  integrity of the frame rate.
00049  *
00050  *  An animation controller is created and destroyed from the animation window.  When an animation controller
00051  *  is destroyed, all animations contained in the controller are also destroyed.
00052  *
00053  *  This subclass of Subject will notify upon the following conditions:
00054  *    - The controller is deleted.
00055  *    - The following methods are called: createAnimation(), setCurrentFrame(),
00056  *      setIntervalMultiplier(), setAnimationState(), setAnimationCycle(), and
00057  *      destroyAnimation().
00058  *    - The frame set in one of the animations changes.
00059  *    - Other notifications documented in the Subject class.
00060  *
00061  *  @see     Animation, AnimationDialog
00062  */
00063 class AnimationController : public SessionItem, public Subject
00064 {
00065 public:
00066    SETTING(FrameSpeedSelection, AnimationController, double, 0)
00067    SETTING(AnimationCycleSelection, AnimationController, AnimationCycle, PLAY_ONCE)
00068    SETTING(CanDropFrames, AnimationController, bool, false)
00069 
00070    /**
00071     *  Emitted with boost::any<std::string> when the controller is renamed.
00072     *
00073     *  @see     AnimationServices::renameAnimationController()
00074     */
00075    SIGNAL_METHOD(AnimationController, Renamed)
00076 
00077    /**
00078     *  Emitted with boost::any<Animation*> when an Animation is added to the
00079     *  controller.
00080     */
00081    SIGNAL_METHOD(AnimationController, AnimationAdded)
00082 
00083    /**
00084     *  Emitted with boost::any<double> when the current frame changes.
00085     *
00086     *  @see getCurrentFrame()
00087     */
00088    SIGNAL_METHOD(AnimationController, FrameChanged)
00089 
00090    /**
00091     *  Emitted with boost::any<double> when the speed multiplier changes.
00092     */
00093    SIGNAL_METHOD(AnimationController, IntervalMultiplierChanged)
00094 
00095    /**
00096     *  Emitted with boost::any<AnimationState> when the animation state of the
00097     *  controller changes.
00098     */
00099    SIGNAL_METHOD(AnimationController, AnimationStateChanged)
00100 
00101    /**
00102     *  Emitted with boost::any<AnimationCycle> when the animation cycle of the
00103     *  controller changes.
00104     */
00105    SIGNAL_METHOD(AnimationController, AnimationCycleChanged)
00106 
00107    /**
00108     *  Emitted with boost::any<Animation*> when an Animation is removed from
00109     *  the controller. This signal will not be emitted when the controller
00110     *  is removing Animations within its destructor.
00111     */
00112    SIGNAL_METHOD(AnimationController, AnimationRemoved)
00113 
00114    /**
00115     *  Emitted when the frame range changes for any reason.
00116     */
00117    SIGNAL_METHOD(AnimationController, FrameRangeChanged)
00118 
00119    /**
00120    *  Emitted with boost::any<bool> when the enabled status of the playback
00121    *  bumpers changes for any reason.
00122    */
00123    SIGNAL_METHOD(AnimationController, BumpersEnabledChanged)
00124 
00125    /**
00126    *  Emitted with boost::any<double> when the start playback bumper changes for any reason.
00127    */
00128    SIGNAL_METHOD(AnimationController, BumperStartChanged)
00129 
00130    /**
00131    *  Emitted with boost::any<double> when the stop playback bumper changes for any reason.
00132    */
00133    SIGNAL_METHOD(AnimationController, BumperStopChanged)
00134 
00135    /**
00136     *  Creates a new animation and adds it to the controller.
00137     *
00138     *  This method creates a new animation with the given name and the same frame type as
00139     *  the controller.  The animation is then added to the internal vector of animations.  The
00140     *  animation name must be unique within the controller.
00141     *
00142     *  @param   name
00143     *           The animation name.  This name cannot be empty and must be unique for all
00144     *           animations in the controller.
00145     *
00146     *  @return  A pointer to the new animation.  NULL is returned if an animation of the given
00147     *           name already exists in the controller.
00148     *
00149     *  @notify  This method will notify signalAnimationAdded() with any<Animation*> after the animation
00150     *           is added to the internal vector.
00151     */
00152    virtual Animation* createAnimation(const std::string& name) = 0;
00153 
00154    /**
00155     *  Retrieves an animation with a given name.
00156     *
00157     *  @param   name
00158     *           The animation name.
00159     *
00160     *  @return  A pointer to the existing animation in the controller.  NULL is returned if no
00161     *           animation exists in the controller with the given name.
00162     */
00163    virtual Animation* getAnimation(const std::string& name) const = 0;
00164 
00165    /**
00166     *  Queries whether an animation with a given name exists in the controller.
00167     *
00168     *  @param   name
00169     *           The animation name.
00170     *
00171     *  @return  True if an animation with the given name exists in the controller, otherwise
00172     *           false.
00173     */
00174    virtual bool hasAnimation(const std::string& name) const = 0;
00175 
00176    /**
00177     *  Retrieves all animations in the controller.
00178     *
00179     *  @return  A const reference to the internal vector of animations.  The vector should
00180     *           not be modified in any way.  To change the contents of the vector, use
00181     *           createAnimation() and destroyAnimation() instead.
00182     */
00183    virtual const std::vector<Animation*>& getAnimations() const = 0;
00184 
00185    /**
00186     *  Returns the number of animations in the controller.
00187     *
00188     *  This is a convenience method that is identical to getAnimations().size().
00189     *
00190     *  @return  The number of animations in the controller.
00191     */
00192    virtual unsigned int getNumAnimations() const = 0;
00193 
00194    /**
00195     *  Removes an existing animation from the controller and deletes it.
00196     *
00197     *  @param   pAnimation
00198     *           The animation to destroy.
00199     *
00200     *  @notify  This method will notify signalAnimationRemoved() with any<Animation*> after the animation
00201     *           has been removed from the controller but before the animation is deleted.  This
00202     *           method will also notify a second time if the result of removing the
00203     *           animation changes the start and/or stop values for the controller.  This
00204     *           notification will occur after the removal notification and before the
00205     *           animation is deleted.
00206     */
00207    virtual void destroyAnimation(Animation* pAnimation) = 0;
00208 
00209    /**
00210     *  Returns the type of frame value that the controller uses to set the current frame
00211     *  in the animations.
00212     *
00213     *  This method returns whether the controller operates on frame numbers or time values
00214     *  when setting the current frame in the animations.  The frame type is specified when
00215     *  the controller is created in AnimationToolBar::createAnimationController().  Once the controller is
00216     *  created, the frame type cannot be changed.
00217     *
00218     *  @return  The animation controller's frame type.
00219     *
00220     *  @see     setCurrentFrame(), getCurrentFrame(), getStartFrame(), getStopFrame()
00221     */
00222    virtual FrameType getFrameType() const = 0;
00223 
00224    /**
00225     *  Sets the current frame value in the controller.
00226     *
00227     *  This method sets the controller's frame value, and automatically sets the current
00228     *  frame in each animation with the given value.  This may or may not actually set the
00229     *  current frame in the animation.  Since the value is the same across all animations in
00230     *  the controller, it is the responsibility of the animation to determine whether or not to
00231     *  update its current frame based on the value.
00232     *
00233     *  @param   frameValue
00234     *           The new frame value for the controller.  The value should correspond to the
00235     *           type returned by getFrameType().
00236     *
00237     *  @notify  This method will notify signalFrameChanged() with any<const AnimationFrame*>.
00238     */
00239    virtual void setCurrentFrame(double frameValue) = 0;
00240 
00241    /**
00242     *  Returns the current frame value in the controller.
00243     *
00244     *  @return  The current frame value.  The value corresponds to the type returned by
00245     *           getFrameType().
00246     */
00247    virtual double getCurrentFrame() const = 0;
00248 
00249    /**
00250     *  Returns the starting frame value in the controller.
00251     *
00252     *  The starting frame value is defined as the minimum frame value across all frames
00253     *  in all animations.
00254     *
00255     *  @return  The starting frame value.  The value corresponds to the type returned by
00256     *           getFrameType().
00257     */
00258    virtual double getStartFrame() const = 0;
00259 
00260    /**
00261     *  Returns the ending frame value in the controller.
00262     *
00263     *  The ending frame value is defined as the maximum frame value across all frames
00264     *  in all animations.
00265     *
00266     *  @return  The ending frame value.  The value corresponds to the type returned by
00267     *           getFrameType().
00268     */
00269    virtual double getStopFrame() const = 0;
00270 
00271    /**
00272     *  Returns the enabled status of the playback bumpers in the controller.
00273     *
00274     *  When the playback bumpers are enabled (status of \c true), the animation playback
00275     *  will be limited to the frame values between the start and stop playback bumpers.
00276     *
00277     *  @return  The enabled status of the playback bumpers.
00278     */
00279    virtual bool getBumpersEnabled() const = 0;
00280 
00281    /**
00282     *  Sets the enabled status of the playback bumpers in the controller.
00283     *
00284     *  When the playback bumpers are enabled (status of \c true), the animation playback
00285     *  will be limited to the frame values between the start and stop playback bumpers.
00286     *
00287     *  @param  enabled
00288     *          The enabled status of the playback bumpers.
00289     *
00290     *  @notify  This method will notify signalBumpersEnabledChanged() with boost::any<bool>.
00291     */
00292    virtual void setBumpersEnabled(bool enabled) = 0;
00293 
00294    /**
00295     *  Returns the start playback bumper value in the controller.
00296     *
00297     *  The start playback bumper value is defined as the first frame value across all frames
00298     *  in all animations that will be played back when the playback bumpers are enabled.
00299     *
00300     *  @return  The start bumper value.  The value corresponds to the type returned by
00301     *           getFrameType().
00302     */
00303    virtual double getStartBumper() const = 0;
00304 
00305    /**
00306     *  Sets the start playback bumper value in the controller.
00307     *
00308     *  The start playback bumper value is defined as the first frame value across all frames
00309     *  in all animations that will be played back when the playback bumpers are enabled.
00310     *
00311     *  @param  frameValue
00312     *          The start bumper value.
00313     *
00314     *  @notify  This method will notify signalBumperStartChanged() with boost::any<double>.
00315     */
00316    virtual void setStartBumper(double frameValue) = 0;
00317 
00318    /**
00319    *  Returns the stop playback bumper value in the controller.
00320    *
00321    *  The stop playback bumper value is defined as the last frame value across all frames
00322    *  in all animations that will be played back when the playback bumpers are enabled.
00323    *
00324    *  @return  The stop bumper value.  The value corresponds to the type returned by
00325    *           getFrameType().
00326    */
00327    virtual double getStopBumper() const = 0;
00328 
00329    /**
00330     *  Sets the stop playback bumper value in the controller.
00331     *
00332     *  The stop playback bumper value is defined as the last frame value across all frames
00333     *  in all animations that will be played back when the playback bumpers are enabled.
00334     *
00335     *  @param  frameValue
00336     *          The stop bumper value.
00337     *
00338     *  @notify  This method will notify signalBumperStopChanged() with boost::any<double>.
00339     */
00340    virtual void setStopBumper(double frameValue) = 0;
00341 
00342    /**
00343     *  Sets the multiplier value associated with the value interval that is used when
00344     *  the controller is advanced.
00345     *
00346     *  This method provides the capability to effectively speed up or slow down the
00347     *  animations.  The interval is defined as the value that is set when the controller is
00348     *  advanced based on the frequency.  The multipler will increase or decrease the
00349     *  interval value used to set the current frame at the same frequency.
00350     *
00351     *  @param   multiplier
00352     *           The value to mutliply the interval by when advancing frames in each
00353     *           animation.  A value between 0.0 and 1.0 will effectively slow down the
00354     *           animations and a value greater than 1.0 will speed up the animations.  This
00355     *           method does nothing if the value is less than or equal to 0.0.  The
00356     *           default multiplier is 1.0.
00357     *
00358     *  @notify  This method will notify signalIntervalMultiplierChanged() with any<double>.
00359     *
00360     *  @see     getFrequency()
00361     */
00362    virtual void setIntervalMultiplier(double multiplier) = 0;
00363 
00364    /**
00365     *  Returns the multiplier value associated with the value interval that is used
00366     *  when the controller is advanced.
00367     *
00368     *  @return  The interval multipler value.
00369     *
00370     *  @see     setIntervalMultiplier()
00371     */
00372    virtual double getIntervalMultiplier() const = 0;
00373 
00374    /**
00375     *  Returns the frequency of when the animations in the controller are updated.
00376     *
00377     *  @return  The frequency of how often animations are updated.
00378     *
00379     *  @see     setIntervalMultiplier()
00380     */
00381    virtual const int getFrequency() const = 0;
00382    
00383    /**
00384     *  Returns the suggested minimum frame rate.
00385     *
00386     *  This is the minimum frame rate needed to completely
00387     *  capture all frames accurately. This defaults to
00388     *  60fps which is currently the highest frame rate a
00389     *  AnimationController can display at 1x playback speed. If
00390     *  a lower minimum frame rate is possible, plug-ins may
00391     *  set the value with setMinimumFrameRate().
00392     *  Frame rates are represented as frames/seconds
00393     *
00394     *  @return The minimum suggested frame rate.
00395     */
00396    virtual boost::rational<int> getMinimumFrameRate() const = 0;
00397    
00398    /**
00399     *  Sets the suggested minimum frame rate.
00400     *
00401     *  This is the minimum frame rate needed to completely
00402     *  capture all frames accurately. This defaults to
00403     *  60fps which is currently the highest frame rate a
00404     *  AnimationController can display at 1x playback speed. If
00405     *  a lower minimum frame rate is possible, plug-ins
00406     *  should set this value.
00407     *  Frame rates are represented as frames/seconds
00408     *
00409     *  @param  frameRate
00410     *          The minimum suggested frame rate.
00411     */
00412    virtual void setMinimumFrameRate(boost::rational<int> frameRate) = 0;
00413 
00414    /**
00415     *  Starts or stops the controller.
00416     *
00417     *  The animation state applies to the controller so all animations are affected by the new
00418     *  state.
00419     *
00420     *  @param   state
00421     *           The new animation state for the controller.
00422     *
00423     *  @notify  This method will notify signalAnimationStateChanged() with any<AnimationState>.
00424     *
00425     *  @see     AnimationState, play(), pause(), stop()
00426     */
00427    virtual void setAnimationState(AnimationState state) = 0;
00428 
00429    /**
00430     *  Returns the current animation state of the controller.
00431     *
00432     *  @return  The current animation state.
00433     *
00434     *  @see     AnimationState
00435     */
00436    virtual AnimationState getAnimationState() const = 0;
00437 
00438    /**
00439     *  Sets the behavior of the controller after the stop frame value is set.
00440     *
00441     *  @param   cycle
00442     *           The new animation cycle for the controller.
00443     *
00444     *  @notify  This method will notify signalAnimationCycleChanged() with any<AnimationCycle>.
00445     *
00446     *  @see     AnimationCycle
00447     */
00448    virtual void setAnimationCycle(AnimationCycle cycle) = 0;
00449 
00450    /**
00451     *  Returns the current animation cycle of the controller.
00452     *
00453     *  @return  The current animation cycle.
00454     *
00455     *  @see     AnimationCycle
00456     */
00457    virtual AnimationCycle getAnimationCycle() const = 0;
00458 
00459    /**
00460     *  Sets the current frame to the starting frame value.
00461     *
00462     *  @see     moveToEnd(), setCurrentFrame()
00463     */
00464    virtual void moveToBeginning() = 0;
00465 
00466    /**
00467     *  Sets the current frame to the ending frame value.
00468     *
00469     *  @see     moveToBeginning(), setCurrentFrame()
00470     */
00471    virtual void moveToEnd() = 0;
00472 
00473    /**
00474     *  Starts playing animations.
00475     *
00476     *  If the controller was previously paused or stopped, the animations play
00477     *  in the forward direction.  If the controller was previously playing
00478     *  backward, it continues to do so.
00479     *
00480     *  @see     fastForward(), fastRewind()
00481     */
00482    virtual void play() = 0;
00483    
00484    /**
00485     *  Stops playing animations without changing the current frame.
00486     *
00487     *  @see     stop()
00488     */
00489    virtual void pause() = 0;
00490 
00491    /**
00492     *  Stops playing animations and changes the current frame.
00493     *
00494     *  After stopping the controller the current frame is changed to the
00495     *  starting frame if the previous animation state was
00496     *  AnimationState::PLAY_FORWARD.  If the previous animation state was
00497     *  AnimationState::PLAY_BACKWARD the current frame is changed to the ending
00498     *  frame.
00499     *
00500     *  @see     pause(), moveToBeginning(), moveToEnd()
00501     */
00502    virtual void stop() = 0;
00503 
00504    /**
00505     *  Sets the interval multiplier and plays in the forward direction.
00506     *
00507     *  @param   multiplier
00508     *           The desired interval multiplier.
00509     *
00510     *  @see     fastRewind(), setIntervalMultiplier()
00511     */
00512    virtual void fastForward(double multiplier) = 0;
00513 
00514    /**
00515     *  Sets the interval multiplier and plays in the backward direction.
00516     *
00517     *  @param   multiplier
00518     *           The desired interval multiplier.
00519     *
00520     *  @see     fastForward(), setIntervalMultiplier()
00521     */
00522    virtual void fastRewind(double multiplier) = 0;
00523 
00524    /**
00525     *  Changes the current frame to the next frame in the frame list.
00526     *
00527     *  The current frame is changed to the next frame in the frame list.
00528     *
00529     *  @see     fastForward(), fastRewind()
00530     */
00531    virtual void stepForward() = 0;
00532 
00533    /**
00534     *  Changes the current frame to the previous frame in the frame list.
00535     *
00536     *  The current frame is changed to the previous frame in the frame list.
00537     *
00538     *  @see     fastForward(), fastRewind()
00539     */
00540    virtual void stepBackward() = 0;
00541 
00542    /**
00543     *  Sets the controller to play the attached animations at without dropping frames.
00544     *
00545     *  Due to system limitations, frames may be dropped in order to achieve the desired
00546     *  play rate.  This method controls whether or not this is allowed.  This is true
00547     *  by default.
00548     *
00549     *  @param   drop
00550     *           True if frames are allowed to be dropped, false otherwise.
00551     */
00552    virtual void setCanDropFrames(bool drop) = 0;
00553 
00554    /**
00555     * Gets whether the controller is allowed to drop frames in order to play at 
00556     * the desired rate.
00557     *
00558     * @return True if the play may drop frames, false otherwise.
00559     *
00560     * @see setCanDropFrames()
00561     */
00562    virtual bool getCanDropFrames() const = 0;
00563 
00564 
00565 protected:
00566    /**
00567     * This should be destroyed by calling AnimationToolbar::destroyAnimationController.
00568     */
00569    virtual ~AnimationController() {}
00570 };
00571 
00572 #endif

Software Development Kit - Opticks 4.9.0 Build 16218