0032742: Coding - get rid of unused headers [Adaptor2d to Approx]
[occt.git] / src / AIS / AIS_AnimationObject.cxx
1 // Created by: Anastasia BORISOVA
2 // Copyright (c) 2016 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
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.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #include <AIS_AnimationObject.hxx>
16
17 #include <AIS_InteractiveContext.hxx>
18 #include <V3d_View.hxx>
19
20 IMPLEMENT_STANDARD_RTTIEXT(AIS_AnimationObject, AIS_Animation)
21
22 //=============================================================================
23 //function : Constructor
24 //purpose  :
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),
33   myObject   (theObject),
34   myTrsfLerp (theTrsfStart, theTrsfEnd)
35 {
36   //
37 }
38
39 //=============================================================================
40 //function : update
41 //purpose  :
42 //=============================================================================
43 void AIS_AnimationObject::update (const AIS_AnimationProgress& theProgress)
44 {
45   if (myObject.IsNull())
46   {
47     return;
48   }
49
50   gp_Trsf aTrsf;
51   myTrsfLerp.Interpolate (theProgress.LocalNormalized, aTrsf);
52   if (!myContext.IsNull())
53   {
54     myContext->SetLocation (myObject, aTrsf);
55     invalidateViewer();
56   }
57   else
58   {
59     myObject->SetLocalTransformation (aTrsf);
60   }
61 }
62
63 //=============================================================================
64 //function : invalidateViewer
65 //purpose  :
66 //=============================================================================
67 void AIS_AnimationObject::invalidateViewer()
68 {
69   if (myContext.IsNull())
70   {
71     return;
72   }
73
74   const Standard_Boolean isImmediate = myContext->CurrentViewer()->ZLayerSettings (myObject->ZLayer()).IsImmediate();
75   if (!isImmediate)
76   {
77     myContext->CurrentViewer()->Invalidate();
78     return;
79   }
80
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())
85   {
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))
92     {
93       if (aZNear < aView->Camera()->ZNear()
94        || aZFar  > aView->Camera()->ZFar())
95       {
96         aDefViewIter.Value()->Invalidate();
97       }
98     }
99   }
100 }