1 // Created by: Anastasia BORISOVA
2 // Copyright (c) 2016 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <AIS_AnimationObject.hxx>
17 #include <AIS_InteractiveContext.hxx>
18 #include <TopLoc_Location.hxx>
19 #include <V3d_Viewer.hxx>
20 #include <V3d_View.hxx>
22 IMPLEMENT_STANDARD_RTTIEXT(AIS_AnimationObject, AIS_Animation)
24 //=============================================================================
25 //function : Constructor
27 //=============================================================================
28 AIS_AnimationObject::AIS_AnimationObject (const TCollection_AsciiString& theAnimationName,
29 const Handle(AIS_InteractiveContext)& theContext,
30 const Handle(AIS_InteractiveObject)& theObject,
31 const gp_Trsf& theTrsfStart,
32 const gp_Trsf& theTrsfEnd)
33 : AIS_Animation (theAnimationName),
34 myContext (theContext),
36 myTrsfLerp (theTrsfStart, theTrsfEnd)
41 //=============================================================================
44 //=============================================================================
45 void AIS_AnimationObject::update (const AIS_AnimationProgress& theProgress)
47 if (myObject.IsNull())
53 myTrsfLerp.Interpolate (theProgress.LocalNormalized, aTrsf);
54 if (!myContext.IsNull())
56 myContext->SetLocation (myObject, aTrsf);
61 myObject->SetLocalTransformation (aTrsf);
65 //=============================================================================
66 //function : invalidateViewer
68 //=============================================================================
69 void AIS_AnimationObject::invalidateViewer()
71 if (myContext.IsNull())
76 const Standard_Boolean isImmediate = myContext->CurrentViewer()->ZLayerSettings (myObject->ZLayer()).IsImmediate();
79 myContext->CurrentViewer()->Invalidate();
83 // Invalidate immediate view only if it is going out of z-fit range.
84 // This might be sub-optimal performing this for each animated objects in case of many animated objects.
85 for (V3d_ListOfView::Iterator aDefViewIter = myContext->CurrentViewer()->DefinedViewIterator();
86 aDefViewIter.More(); aDefViewIter.Next())
88 const Handle(V3d_View)& aView = aDefViewIter.Value();
89 const Bnd_Box aMinMaxBox = aView->View()->MinMaxValues (Standard_False);
90 const Bnd_Box aGraphicBox = aView->View()->MinMaxValues (Standard_True);
91 Standard_Real aZNear = 0.0;
92 Standard_Real aZFar = 0.0;
93 if (aView->Camera()->ZFitAll (aDefViewIter.Value()->AutoZFitScaleFactor(), aMinMaxBox, aGraphicBox, aZNear, aZFar))
95 if (aZNear < aView->Camera()->ZNear()
96 || aZFar > aView->Camera()->ZFar())
98 aDefViewIter.Value()->Invalidate();