0028010: Visualization, Prs3d_Arrow - add Shading presentation builder
[occt.git] / src / AIS / AIS_AnimationObject.cxx
CommitLineData
1beb58d7 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 <TopLoc_Location.hxx>
19#include <V3d_Viewer.hxx>
20#include <V3d_View.hxx>
21
22IMPLEMENT_STANDARD_RTTIEXT(AIS_AnimationObject, AIS_Animation)
23
24//=============================================================================
25//function : Constructor
26//purpose :
27//=============================================================================
28AIS_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),
35 myObject (theObject),
36 myTrsfLerp (theTrsfStart, theTrsfEnd)
37{
38 //
39}
40
41//=============================================================================
42//function : update
43//purpose :
44//=============================================================================
45void AIS_AnimationObject::update (const AIS_AnimationProgress& theProgress)
46{
47 if (myObject.IsNull())
48 {
49 return;
50 }
51
52 gp_Trsf aTrsf;
53 myTrsfLerp.Interpolate (theProgress.LocalNormalized, aTrsf);
54 if (!myContext.IsNull())
55 {
56 myContext->SetLocation (myObject, aTrsf);
57 invalidateViewer();
58 }
59 else
60 {
61 myObject->SetLocalTransformation (aTrsf);
62 }
63}
64
65//=============================================================================
66//function : invalidateViewer
67//purpose :
68//=============================================================================
69void AIS_AnimationObject::invalidateViewer()
70{
71 if (myContext.IsNull())
72 {
73 return;
74 }
75
76 const Standard_Boolean isImmediate = myContext->CurrentViewer()->ZLayerSettings (myObject->ZLayer()).IsImmediate();
77 if (!isImmediate)
78 {
79 myContext->CurrentViewer()->Invalidate();
80 return;
81 }
82
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())
87 {
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))
94 {
95 if (aZNear < aView->Camera()->ZNear()
96 || aZFar > aView->Camera()->ZFar())
97 {
98 aDefViewIter.Value()->Invalidate();
99 }
100 }
101 }
102}