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 <V3d_View.hxx>
20 IMPLEMENT_STANDARD_RTTIEXT(AIS_AnimationObject, AIS_Animation)
22 //=============================================================================
23 //function : Constructor
25 //=============================================================================
26 AIS_AnimationObject::AIS_AnimationObject (const TCollection_AsciiString& theAnimationName,
27 const Handle(AIS_InteractiveContext)& theContext,
28 const Handle(AIS_InteractiveObject)& theObject,
29 const gp_Trsf& theTrsfStart,
30 const gp_Trsf& theTrsfEnd)
31 : AIS_Animation (theAnimationName),
32 myContext (theContext),
34 myTrsfLerp (theTrsfStart, theTrsfEnd)
39 //=============================================================================
42 //=============================================================================
43 void AIS_AnimationObject::update (const AIS_AnimationProgress& theProgress)
45 if (myObject.IsNull())
51 myTrsfLerp.Interpolate (theProgress.LocalNormalized, aTrsf);
52 if (!myContext.IsNull())
54 myContext->SetLocation (myObject, aTrsf);
59 myObject->SetLocalTransformation (aTrsf);
63 //=============================================================================
64 //function : invalidateViewer
66 //=============================================================================
67 void AIS_AnimationObject::invalidateViewer()
69 if (myContext.IsNull())
74 const Standard_Boolean isImmediate = myContext->CurrentViewer()->ZLayerSettings (myObject->ZLayer()).IsImmediate();
77 myContext->CurrentViewer()->Invalidate();
81 // Invalidate immediate view only if it is going out of z-fit range.
82 // This might be sub-optimal performing this for each animated objects in case of many animated objects.
83 for (V3d_ListOfView::Iterator aDefViewIter = myContext->CurrentViewer()->DefinedViewIterator();
84 aDefViewIter.More(); aDefViewIter.Next())
86 const Handle(V3d_View)& aView = aDefViewIter.Value();
87 const Bnd_Box aMinMaxBox = aView->View()->MinMaxValues (Standard_False);
88 const Bnd_Box aGraphicBox = aView->View()->MinMaxValues (Standard_True);
89 Standard_Real aZNear = 0.0;
90 Standard_Real aZFar = 0.0;
91 if (aView->Camera()->ZFitAll (aDefViewIter.Value()->AutoZFitScaleFactor(), aMinMaxBox, aGraphicBox, aZNear, aZFar))
93 if (aZNear < aView->Camera()->ZNear()
94 || aZFar > aView->Camera()->ZFar())
96 aDefViewIter.Value()->Invalidate();