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