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 //======================================================================= ViewerTest_AutoUpdater(const Handle (AIS_InteractiveContext)& theContext,const Handle (V3d_View)& theView)22ViewerTest_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 //======================================================================= ~ViewerTest_AutoUpdater()39ViewerTest_AutoUpdater::~ViewerTest_AutoUpdater() 40 { 41 Update(); 42 } 43 44 //======================================================================= 45 //function : parseRedrawMode 46 //purpose : 47 //======================================================================= parseRedrawMode(const TCollection_AsciiString & theArg)48Standard_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 //======================================================================= Invalidate()71void ViewerTest_AutoUpdater::Invalidate() 72 { 73 myToUpdate = ViewerTest_AutoUpdater::RedrawMode_Suppressed; 74 if (myWasAutoUpdate 75 && !myView.IsNull()) 76 { 77 myView->SetImmediateUpdate (myWasAutoUpdate); 78 } 79 } 80 81 //======================================================================= 82 //function : Update 83 //purpose : 84 //======================================================================= Update()85void ViewerTest_AutoUpdater::Update() 86 { 87 if (!myView.IsNull()) 88 { 89 myView->SetImmediateUpdate (myWasAutoUpdate); 90 } 91 92 switch (myToUpdate) 93 { 94 case ViewerTest_AutoUpdater::RedrawMode_Suppressed: 95 { 96 return; 97 } 98 case ViewerTest_AutoUpdater::RedrawMode_Auto: 99 { 100 if (!myWasAutoUpdate) 101 { 102 return; 103 } 104 } 105 Standard_FALLTHROUGH 106 case ViewerTest_AutoUpdater::RedrawMode_Forced: 107 { 108 if (!myContext.IsNull()) 109 { 110 myContext->UpdateCurrentViewer(); 111 } 112 else if (!myView.IsNull()) 113 { 114 myView->Redraw(); 115 } 116 } 117 } 118 } 119