Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:02:54

0001 // Created by: Anastasia BORISOVA
0002 // Copyright (c) 2016 OPEN CASCADE SAS
0003 //
0004 // This file is part of Open CASCADE Technology software library.
0005 //
0006 // This library is free software; you can redistribute it and/or modify it under
0007 // the terms of the GNU Lesser General Public License version 2.1 as published
0008 // by the Free Software Foundation, with special exception defined in the file
0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0010 // distribution for complete text of the license and disclaimer of any warranty.
0011 //
0012 // Alternatively, this file may be used under the terms of Open CASCADE
0013 // commercial license or contractual agreement.
0014 
0015 #ifndef _AIS_Animation_HeaderFile
0016 #define _AIS_Animation_HeaderFile
0017 
0018 #include <AIS_AnimationTimer.hxx>
0019 #include <NCollection_Sequence.hxx>
0020 #include <TCollection_AsciiString.hxx>
0021 
0022 //! Structure defining current animation progress.
0023 struct AIS_AnimationProgress
0024 {
0025   Standard_Real Pts;             //!< global presentation timestamp
0026   Standard_Real LocalPts;        //!< presentation within current animation
0027   Standard_Real LocalNormalized; //!< normalized position within current animation within 0..1 range
0028 
0029   AIS_AnimationProgress() : Pts (-1.0), LocalPts (-1.0), LocalNormalized (-1.0) {}
0030 };
0031 
0032 DEFINE_STANDARD_HANDLE(AIS_Animation, Standard_Transient)
0033 
0034 //! Class represents a basic animation class.
0035 //! AIS_Animation can be used as:
0036 //!
0037 //! - Animation Implementor
0038 //!   Sub-classes should override method AIS_Animation::update() to perform specific animation.
0039 //!   AIS package provides limited number of such animation atoms - classes AIS_AnimationObject and AIS_AnimationCamera, which could be enough for defining a simple animation.
0040 //!   In general case, application is expected defining own AIS_Animation sub-classes implementing application-specific animation logic
0041 //!   (e.g. another interpolation or another kind of transformations - like color transition and others).
0042 //!   The basic conception of AIS_Animation::update() is defining an exact scene state for the current presentation timestamp,
0043 //!   providing a smooth and continuous animation well defined at any time step and in any direction.
0044 //!   So that a time difference between two sequential drawn Viewer frames can vary from frame to frame without visual artifacts,
0045 //!   increasing rendering framerate would not lead to animation being executed too fast
0046 //!   and low framerate (on slow hardware) would not lead to animation played longer than defined duration.
0047 //!   Hence, implementation should avoid usage of incremental step logic or should apply it very carefully.
0048 //!
0049 //! - Animation Container
0050 //!   AIS_Animation (no sub-classing) can be used to aggregate a sequence of Animation items (children).
0051 //!   Each children should be defined with its own duration and start time (presentation timestamp).
0052 //!   It is possible defining collection of nested AIS_Animation items, so that within each container level
0053 //!   children define start playback time relative to its holder.
0054 //!
0055 //! - Animation playback Controller
0056 //!   It is suggested that application would define a single AIS_Animation instance (optional sub-classing) for controlling animation playback as whole.
0057 //!   Such controller should be filled in by other AIS_Animation as children objects,
0058 //!   and will be managed by application by calling StartTimer(), UpdateTimer() and IsStopped() methods.
0059 //!
0060 //! Note, that AIS_Animation::StartTimer() defines a timer calculating an elapsed time, not a multimedia timer executing Viewer updates at specific intervals!
0061 //! Application should avoid using implicit and immediate Viewer updates to ensure that AIS_Animation::UpdateTimer() is called before each redrawing of a Viewer content.
0062 //! Redrawing logic should be also managed at application level for managing a smooth animation
0063 //! (by defining a multimedia timer provided by used GUI framework executing updates at desired framerate, or as continuous redraws in loop).
0064 class AIS_Animation : public Standard_Transient
0065 {
0066   DEFINE_STANDARD_RTTIEXT(AIS_Animation, Standard_Transient)
0067 public:
0068 
0069   //! Creates empty animation.
0070   Standard_EXPORT AIS_Animation (const TCollection_AsciiString& theAnimationName);
0071 
0072   //! Destruct object, clear arguments
0073   Standard_EXPORT virtual ~AIS_Animation();
0074 
0075   //! Animation name.
0076   const TCollection_AsciiString& Name() const { return myName; }
0077 
0078 public:
0079 
0080   //! @return start time of the animation in the timeline
0081   Standard_Real StartPts() const { return myPtsStart; }
0082 
0083   //! Sets time limits for animation in the animation timeline
0084   void SetStartPts (const Standard_Real thePtsStart) { myPtsStart = thePtsStart; }
0085 
0086   //! @return duration of the animation in the timeline
0087   Standard_Real Duration() const { return Max (myOwnDuration, myChildrenDuration); }
0088 
0089   //! Update total duration considering all animations on timeline.
0090   Standard_EXPORT void UpdateTotalDuration();
0091 
0092   //! Return true if duration is defined.
0093   Standard_Boolean HasOwnDuration() const { return myOwnDuration > 0.0; }
0094 
0095   //! @return own duration of the animation in the timeline
0096   Standard_Real OwnDuration() const { return myOwnDuration; }
0097 
0098   //! Defines duration of the animation.
0099   void SetOwnDuration (const Standard_Real theDuration) { myOwnDuration = theDuration; }
0100 
0101   //! Add single animation to the timeline.
0102   //! @param theAnimation input animation
0103   Standard_EXPORT void Add (const Handle(AIS_Animation)& theAnimation);
0104 
0105   //! Clear animation timeline - remove all animations from it.
0106   Standard_EXPORT void Clear();
0107 
0108   //! Return the child animation with the given name.
0109   Standard_EXPORT Handle(AIS_Animation) Find (const TCollection_AsciiString& theAnimationName) const;
0110 
0111   //! Remove the child animation.
0112   Standard_EXPORT Standard_Boolean Remove (const Handle(AIS_Animation)& theAnimation);
0113 
0114   //! Replace the child animation.
0115   Standard_EXPORT Standard_Boolean Replace (const Handle(AIS_Animation)& theAnimationOld,
0116                                             const Handle(AIS_Animation)& theAnimationNew);
0117 
0118   //! Clears own children and then copy child animations from another object.
0119   //! Copy also Start Time and Duration values.
0120   Standard_EXPORT void CopyFrom (const Handle(AIS_Animation)& theOther);
0121 
0122   //! Return sequence of child animations.
0123   const NCollection_Sequence<Handle(AIS_Animation)>& Children() const { return myAnimations; }
0124 
0125 public:
0126 
0127   //! Start animation with internally defined timer instance.
0128   //! Calls ::Start() internally.
0129   //!
0130   //! Note, that this method initializes a timer calculating an elapsed time (presentation timestamps within AIS_Animation::UpdateTimer()),
0131   //! not a multimedia timer executing Viewer updates at specific intervals!
0132   //! Viewer redrawing should be managed at application level, so that AIS_Animation::UpdateTimer() is called once right before each redrawing of a Viewer content.
0133   //!
0134   //! @param theStartPts    starting timer position (presentation timestamp)
0135   //! @param thePlaySpeed   playback speed (1.0 means normal speed)
0136   //! @param theToUpdate    flag to update defined animations to specified start position
0137   //! @param theToStopTimer flag to pause timer at the starting position
0138   Standard_EXPORT virtual void StartTimer (const Standard_Real    theStartPts,
0139                                            const Standard_Real    thePlaySpeed,
0140                                            const Standard_Boolean theToUpdate,
0141                                            const Standard_Boolean theToStopTimer = Standard_False);
0142 
0143   //! Update single frame of animation, update timer state
0144   //! @return current time of timeline progress.
0145   Standard_EXPORT virtual Standard_Real UpdateTimer();
0146 
0147   //! Return elapsed time.
0148   Standard_Real ElapsedTime() const { return !myTimer.IsNull() ? myTimer->ElapsedTime() : 0.0; }
0149 
0150   //! Return playback timer.
0151   const Handle(Media_Timer)& Timer() const { return myTimer; }
0152 
0153   //! Set playback timer.
0154   void SetTimer (const Handle(Media_Timer)& theTimer) { myTimer = theTimer; }
0155 
0156 public:
0157 
0158   //! Start animation. This method changes status of the animation to Started.
0159   //! This status defines whether animation is to be performed in the timeline or not.
0160   //! @param theToUpdate call Update() method
0161   Standard_EXPORT virtual void Start (const Standard_Boolean theToUpdate);
0162 
0163   //! Pause the process timeline.
0164   Standard_EXPORT virtual void Pause();
0165 
0166   //! Stop animation. This method changed status of the animation to Stopped.
0167   //! This status shows that animation will not be performed in the timeline or it is finished.
0168   Standard_EXPORT virtual void Stop();
0169 
0170   //! Check if animation is to be performed in the animation timeline.
0171   //! @return True if it is stopped of finished.
0172   bool IsStopped() { return myState != AnimationState_Started; }
0173 
0174   //! Update single frame of animation, update timer state
0175   //! @param thePts [in] the time moment within [0; Duration()]
0176   //! @return True if timeline is in progress
0177   Standard_EXPORT virtual Standard_Boolean Update (const Standard_Real thePts);
0178 
0179 protected:
0180 
0181   //! Process one step of the animation according to the input time progress, including all children.
0182   //! Calls also ::update() to update own animation.
0183   Standard_EXPORT virtual void updateWithChildren (const AIS_AnimationProgress& thePosition);
0184 
0185   //! Update the own animation to specified position - should be overridden by sub-class.
0186   virtual void update (const AIS_AnimationProgress& theProgress) { (void )theProgress; }
0187 
0188 protected:
0189 
0190   //! Defines animation state.
0191   enum AnimationState
0192   {
0193     AnimationState_Started, //!< animation is in progress
0194     AnimationState_Stopped, //!< animation is finished, force stopped or not started
0195     AnimationState_Paused   //!< animation is paused and can be started from the pause moment
0196   };
0197 
0198 protected:
0199 
0200   Handle(Media_Timer) myTimer;
0201 
0202   TCollection_AsciiString myName;           //!< animation name
0203   NCollection_Sequence<Handle(AIS_Animation)>
0204                         myAnimations;       //!< sequence of child animations
0205 
0206   AnimationState        myState;            //!< animation state - started, stopped of paused
0207   Standard_Real         myPtsStart;         //!< time of start in the timeline
0208   Standard_Real         myOwnDuration;      //!< duration of animation excluding children
0209   Standard_Real         myChildrenDuration; //!< duration of animation including children
0210 
0211 };
0212 
0213 #endif // _AIS_Animation_HeaderFile