0025198: Draw Harness - add -noupdate option to vsetlocation command
[occt.git] / src / ViewerTest / ViewerTest_AutoUpdater.cxx
1 // Created on: 2014-04-24
2 // Created by: Kirill Gavrilov
3 // Copyright (c) 2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <ViewerTest_AutoUpdater.hxx>
17
18 //=======================================================================
19 //function : ViewerTest_AutoUpdater
20 //purpose  :
21 //=======================================================================
22 ViewerTest_AutoUpdater::ViewerTest_AutoUpdater (const Handle(AIS_InteractiveContext)& theContext,
23                                                 const Handle(V3d_View)&               theView)
24 : myContext       (theContext),
25   myView          (theView),
26   myToUpdate      (RedrawMode_Auto),
27   myWasAutoUpdate (Standard_False)
28 {
29   if (!theView.IsNull())
30   {
31     myWasAutoUpdate = theView->SetImmediateUpdate (Standard_False);
32   }
33 }
34
35 //=======================================================================
36 //function : ~ViewerTest_AutoUpdater
37 //purpose  :
38 //=======================================================================
39 ViewerTest_AutoUpdater::~ViewerTest_AutoUpdater()
40 {
41   Update();
42 }
43
44 //=======================================================================
45 //function : parseRedrawMode
46 //purpose  :
47 //=======================================================================
48 Standard_Boolean ViewerTest_AutoUpdater::parseRedrawMode (const TCollection_AsciiString& theArg)
49 {
50   TCollection_AsciiString anArgCase (theArg);
51   anArgCase.LowerCase();
52   if (anArgCase == "-update"
53    || anArgCase == "-redraw")
54   {
55     myToUpdate = RedrawMode_Forced;
56     return Standard_True;
57   }
58   else if (anArgCase == "-noupdate"
59         || anArgCase == "-noredraw")
60   {
61     myToUpdate = RedrawMode_Suppressed;
62     return Standard_True;
63   }
64   return Standard_False;
65 }
66
67 //=======================================================================
68 //function : Invalidate
69 //purpose  :
70 //=======================================================================
71 void ViewerTest_AutoUpdater::Invalidate()
72 {
73   myContext.Nullify();
74   if (myWasAutoUpdate)
75   {
76     myView->SetImmediateUpdate (myWasAutoUpdate);
77   }
78 }
79
80 //=======================================================================
81 //function : Update
82 //purpose  :
83 //=======================================================================
84 void ViewerTest_AutoUpdater::Update()
85 {
86   if (myContext.IsNull())
87   {
88     return;
89   }
90
91   // update the screen and redraw the view
92   myView->SetImmediateUpdate (myWasAutoUpdate);
93   if ((myWasAutoUpdate && myToUpdate != ViewerTest_AutoUpdater::RedrawMode_Suppressed)
94     || myToUpdate == ViewerTest_AutoUpdater::RedrawMode_Forced)
95   {
96     myContext->UpdateCurrentViewer();
97   }
98 }