--- /dev/null
+# test performance of display of heavy scene involving multiple interactive
+# objects, on example of 1000 spheres
+
+pload MODELING
+pload VISUALIZATION
+
+vinit View1 w=1024 h=1024
+vclear
+
+# parameter NB defines number of spheres by each coordinate
+set NB 10
+puts "Creating [expr $NB * $NB * $NB] spheres..."
+set slist {}
+for {set i 0} {$i < $NB} {incr i} {
+ for {set j 0} {$j < $NB} {incr j} {
+ for {set k 0} {$k < $NB} {incr k} {
+ psphere s$i$j$k 1.
+ lappend slist s$i$j$k
+ ttranslate s$i$j$k 3.*$i 3.*$j 3.*$k
+ }
+ }
+}
+
+puts "Measuring FPS of display of spheres as separate objects..."
+vaxo
+vsetdispmode 1
+eval vdisplay $slist
+vfit
+
+# measure FPS
+puts [set fps_separate [vfps]]
+vclear
+
+puts "Measuring FPS of display of spheres as single object..."
+eval compound $slist c
+vdisplay c
+
+# measure FPS
+puts [set fps_compound [vfps]]
+vclear
+
+# redisplay individual spheres, trying to avoid unnecessary internal updates
+#vfrustumculling 0 ;# try to disable updates of frustum culling structures
+eval vdisplay -mutable $slist
+
+# auxiliary procedure to make random update of variable
+proc upd {theValueName theDeltaName theTime theToRand} {
+ upvar $theValueName aValue
+ upvar $theDeltaName aDelta
+
+ # set colors to corner spheres
+ if { $theToRand == 1 } {
+ set aValue [expr $aValue + $aDelta * $theTime / 100.0]
+ set aDelta [expr 0.5 * (rand() - 0.5)]
+ return $aValue
+ }
+
+ set aRes [expr $aValue + $aDelta * $theTime / 100.0]
+}
+
+# move corner spheres in cycle
+proc animateSpheres {{theDuration 10.0}} {
+ set nb [expr $::NB - 1]
+
+ # set colors to corner spheres
+ for {set i 0} {$i < $::NB} {incr i $nb} {
+ for {set j 0} {$j < $::NB} {incr j $nb} {
+ for {set k 0} {$k < $::NB} {incr k $nb} {
+# vaspects -noupdate s$i$j$k -setcolor red -setmaterial plastic
+ vaspects -noupdate s$i$j$k -setcolor red
+ set x$i$j$k 0.0
+ set y$i$j$k 0.0
+ set z$i$j$k 0.0
+ set dx$i$j$k 0.0
+ set dy$i$j$k 0.0
+ set dz$i$j$k 0.0
+ }
+ }
+ }
+
+ set aDuration 0.0
+ set aPrevRand 0.0
+ set aTimeFrom [clock clicks -milliseconds]
+ uplevel #0 chrono anAnimTimer reset
+ uplevel #0 chrono anAnimTimer start
+ set toRand 1
+ for {set aFrameIter 1} { $aFrameIter > 0 } {incr aFrameIter} {
+ set aCurrTime [expr [clock clicks -milliseconds] - $aTimeFrom]
+ if { $aCurrTime >= [expr $theDuration * 1000.0] } {
+ puts "Nb Frames: $aFrameIter"
+ puts "Duration: [expr $aCurrTime * 0.001] s"
+ set fps [expr ($aFrameIter - 1) / ($aDuration * 0.001) ]
+ puts "FPS: $fps"
+ uplevel #0 chrono anAnimTimer stop
+ uplevel #0 chrono anAnimTimer show
+ return $fps
+ }
+
+ set aRandTime [expr $aCurrTime - $aPrevRand]
+ if { $aRandTime > 1000 } {
+ set toRand 1
+ set aPrevRand $aCurrTime
+ }
+
+ #puts "PTS: $aCurrTime ms"
+ for {set i 0} {$i < $::NB} {incr i $nb} {
+ for {set j 0} {$j < $::NB} {incr j $nb} {
+ for {set k 0} {$k < $::NB} {incr k $nb} {
+ uplevel #0 vsetlocation -noupdate s$i$j$k [upd x$i$j$k dx$i$j$k $aRandTime $toRand] [upd y$i$j$k dy$i$j$k $aRandTime $toRand] [upd z$i$j$k dz$i$j$k $aRandTime $toRand]
+ }
+ }
+ }
+ uplevel #0 vrepaint
+ set aDuration [expr [clock clicks -milliseconds] - $aTimeFrom]
+ set toRand 0
+
+ # sleep 1 ms allowing the user to interact with the viewer
+ after 1 set waiter 1
+ vwait waiter
+ }
+}
+
+puts "Animating movements of corner spheres (10 sec)..."
+puts "(you can interact with the view during the process)"
+set fps_animation [animateSpheres 10.0]
+
+puts ""
+puts "Performance counters (FPS = \"Frames per second\"):"
+puts ""
+puts "Spheres as separate interactive objects:"
+puts " Actual FPS: [lindex $fps_separate 1]"
+puts " FPS estimate by CPU load: [expr 1000. / [lindex $fps_separate 3]]"
+puts ""
+puts "Spheres as one interactive object (compound):"
+puts " Actual FPS: [lindex $fps_compound 1]"
+puts " FPS estimate by CPU load: [expr 1000. / [lindex $fps_compound 3]]"
+puts ""
+puts "Animation FPS: $fps_animation"
+puts ""
+puts "Scene contains [lindex [trinfo c] 3] triangles"
+puts ""
+puts "Print 'animateSpheres 10.0' to restart animation"
\ No newline at end of file
#include <Standard_Stream.hxx>
#include <ViewerTest.hxx>
+
#include <TopLoc_Location.hxx>
#include <TopTools_HArray1OfShape.hxx>
#include <TColStd_HArray1OfTransient.hxx>
#include <Prs3d_ShadingAspect.hxx>
#include <Prs3d_IsoAspect.hxx>
#include <TopTools_MapOfShape.hxx>
+#include <ViewerTest_AutoUpdater.hxx>
#include <stdio.h>
#include <Draw_Interpretor.hxx>
#include <TCollection_AsciiString.hxx>
#include <Draw_PluginMacro.hxx>
-#include <ViewerTest.hxx>
// avoid warnings on 'extern "C"' functions returning C++ classes
#ifdef WNT
#define DEFAULT_COLOR Quantity_NOC_GOLDENROD
#define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
-enum ViewerTest_RedrawMode
-{
- ViewerTest_RM_Auto = -1,
- ViewerTest_RM_RedrawForce,
- ViewerTest_RM_RedrawSuppress
-};
-
-//! Auxiliary method to parse redraw mode argument
-static Standard_Boolean parseRedrawMode (const TCollection_AsciiString& theArg,
- ViewerTest_RedrawMode& theMode)
-{
- TCollection_AsciiString anArgCase (theArg);
- anArgCase.LowerCase();
- if (anArgCase == "-update"
- || anArgCase == "-redraw")
- {
- theMode = ViewerTest_RM_RedrawForce;
- return Standard_True;
- }
- else if (anArgCase == "-noupdate"
- || anArgCase == "-noredraw")
- {
- theMode = ViewerTest_RM_RedrawSuppress;
- return Standard_True;
- }
- return Standard_False;
-}
-
//=======================================================================
//function : GetColorFromName
//purpose : get the Quantity_NameOfColor from a string
const char** theArgVec)
{
const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
+ ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
if (aCtx.IsNull())
{
std::cerr << "Error: no active view!\n";
return 1;
}
- ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
- Standard_Integer anArgIter = 1;
+ Standard_Integer anArgIter = 1;
for (; anArgIter < theArgNb; ++anArgIter)
{
- if (!parseRedrawMode (theArgVec[anArgIter], aToUpdate))
+ if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
{
break;
}
aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
}
}
-
- // update the screen and redraw the view
- const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
- a3DView()->SetImmediateUpdate (isAutoUpdate);
- if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
- || aToUpdate == ViewerTest_RM_RedrawForce)
- {
- TheAISContext()->UpdateCurrentViewer();
- }
return 0;
}
{
TCollection_AsciiString aCmdName (theArgVec[0]);
const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
+ ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
if (aCtx.IsNull())
{
std::cerr << "Error: no active view!\n";
return 1;
}
- ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
- Standard_Integer anArgIter = 1;
+ Standard_Integer anArgIter = 1;
NCollection_Sequence<TCollection_AsciiString> aNames;
for (; anArgIter < theArgNb; ++anArgIter)
{
TCollection_AsciiString anArg = theArgVec[anArgIter];
- if (parseRedrawMode (anArg, aToUpdate))
+ if (anUpdateTool.parseRedrawMode (anArg))
{
continue;
}
}
}
}
-
- // update the screen and redraw the view
- const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
- a3DView()->SetImmediateUpdate (isAutoUpdate);
- if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
- || aToUpdate == ViewerTest_RM_RedrawForce)
- {
- TheAISContext()->UpdateCurrentViewer();
- }
return 0;
}
const char** theArgVec)
{
const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
+ ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
if (aCtx.IsNull())
{
std::cerr << "Error: no active view!\n";
{
aCtx->CloseLocalContext();
}
- ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
Standard_Integer anArgIter = 1;
for (; anArgIter < theArgNb; ++anArgIter)
{
- if (!parseRedrawMode (theArgVec[anArgIter], aToUpdate))
+ if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
{
break;
}
TheNISContext()->Erase (aShape);
}
}
-
- // update the screen and redraw the view
- const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
- a3DView()->SetImmediateUpdate (isAutoUpdate);
- if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
- || aToUpdate == ViewerTest_RM_RedrawForce)
- {
- TheAISContext()->UpdateCurrentViewer();
- }
-
return 0;
}
Standard_Integer theArgNb,
const char** theArgVec)
{
- if (a3DView().IsNull())
+ const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
+ ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
+ if (aCtx.IsNull())
{
- std::cout << "Error: wrong syntax!\n";
+ std::cout << "Error: no active view!\n";
return 1;
}
- TheAISContext()->CloseAllContexts (Standard_False);
+ aCtx->CloseAllContexts (Standard_False);
- ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
- Standard_Boolean isContextOnly = Standard_False;
- Standard_Boolean toRemoveAll = Standard_False;
- Standard_Boolean toPrintInfo = Standard_True;
+ Standard_Boolean isContextOnly = Standard_False;
+ Standard_Boolean toRemoveAll = Standard_False;
+ Standard_Boolean toPrintInfo = Standard_True;
Standard_Integer anArgIter = 1;
for (; anArgIter < theArgNb; ++anArgIter)
{
toPrintInfo = Standard_False;
}
- else if (!parseRedrawMode (anArg, aToUpdate))
+ else if (!anUpdateTool.parseRedrawMode (anArg))
{
break;
}
const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (aTransientObj);
if (!anIO.IsNull())
{
- if (anIO->GetContext() != TheAISContext())
+ if (anIO->GetContext() != aCtx)
{
theDI << aName.ToCString() << " was not displayed in current context.\n";
theDI << "Please activate view with this object displayed and try again.\n";
}
}
}
- else if (TheAISContext()->NbCurrents() > 0
+ else if (aCtx->NbCurrents() > 0
|| TheNISContext()->GetSelected().Extent() > 0)
{
for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
if (!anIO.IsNull())
{
- if (!TheAISContext()->IsCurrent (anIO))
+ if (!aCtx->IsCurrent (anIO))
{
continue;
}
const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
if (!anIO.IsNull())
{
- TheAISContext()->Remove (anIO, Standard_False);
+ aCtx->Remove (anIO, Standard_False);
if (toPrintInfo)
{
theDI << anIter.Value().ToCString() << " was removed\n";
GetMapOfAIS().UnBind2 (anIter.Value());
}
}
-
- // update the screen and redraw the view
- const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
- a3DView()->SetImmediateUpdate (isAutoUpdate);
- if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
- || aToUpdate == ViewerTest_RM_RedrawForce)
- {
- TheAISContext()->UpdateCurrentViewer();
- }
-
return 0;
}
Standard_Integer theArgNb,
const char** theArgVec)
{
- if (a3DView().IsNull())
+ const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
+ ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
+ if (aCtx.IsNull())
{
std::cout << "Error: no active view!\n";
return 1;
}
- TheAISContext()->CloseAllContexts (Standard_False);
+ aCtx->CloseAllContexts (Standard_False);
- ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
Standard_Integer anArgIter = 1;
for (; anArgIter < theArgNb; ++anArgIter)
{
- if (!parseRedrawMode (theArgVec[anArgIter], aToUpdate))
+ if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
{
break;
}
theDI << aName.ToCString() << " ";
if (!anIO.IsNull())
{
- TheAISContext()->Erase (anIO, Standard_False);
+ aCtx->Erase (anIO, Standard_False);
}
else
{
}
}
else if (!toEraseAll
- && TheAISContext()->NbCurrents() > 0)
+ && aCtx->NbCurrents() > 0)
{
// remove all currently selected objects
for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
{
const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
if (!anIO.IsNull()
- && TheAISContext()->IsCurrent (anIO))
+ && aCtx->IsCurrent (anIO))
{
theDI << anIter.Key2().ToCString() << " ";
- TheAISContext()->Erase (anIO, Standard_False);
+ aCtx->Erase (anIO, Standard_False);
}
}
}
const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
if (!anIO.IsNull())
{
- TheAISContext()->Erase (anIO, Standard_False);
+ aCtx->Erase (anIO, Standard_False);
}
else
{
}
}
}
-
- // update the screen and redraw the view
- const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
- a3DView()->SetImmediateUpdate (isAutoUpdate);
- if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
- || aToUpdate == ViewerTest_RM_RedrawForce)
- {
- TheAISContext()->UpdateCurrentViewer();
- }
-
return 0;
}
const char** theArgVec)
{
- if (a3DView().IsNull())
+ const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
+ ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
+ if (aCtx.IsNull())
{
std::cout << "Error: no active view!\n";
return 1;
}
- ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
-
Standard_Integer anArgIter = 1;
for (; anArgIter < theArgNb; ++anArgIter)
{
- if (!parseRedrawMode (theArgVec[anArgIter], aToUpdate))
+ if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
{
break;
}
return 1;
}
- if (TheAISContext()->HasOpenedContext())
+ if (aCtx->HasOpenedContext())
{
- TheAISContext()->CloseLocalContext();
+ aCtx->CloseLocalContext();
}
for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
{
const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
- TheAISContext()->Erase (aShape, Standard_False);
+ aCtx->Erase (aShape, Standard_False);
}
else if (anIter.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject)))
{
if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
{
const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
- TheAISContext()->Display (aShape, Standard_False);
+ aCtx->Display (aShape, Standard_False);
}
else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
{
TheNISContext()->Display (aShape);
}
}
-
- // update the screen and redraw the view
- const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
- a3DView()->SetImmediateUpdate (isAutoUpdate);
- if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
- || aToUpdate == ViewerTest_RM_RedrawForce)
- {
- TheAISContext()->UpdateCurrentViewer();
- }
-
return 0;
}
const char** theArgVec)
{
Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
+ ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
if (aCtx.IsNull())
{
std::cout << "Error: no active view!\n";
return 1;
}
- ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
- ViewerTest_BndAction anAction = BndAction_Show;
- Standard_Integer aMode = -1;
+ ViewerTest_BndAction anAction = BndAction_Show;
+ Standard_Integer aMode = -1;
Standard_Integer anArgIter = 1;
for (; anArgIter < theArgNb; ++anArgIter)
}
aMode = Draw::Atoi (theArgVec[anArgIter]);
}
- else if (!parseRedrawMode (anArg, aToUpdate))
+ else if (!anUpdateTool.parseRedrawMode (anArg))
{
break;
}
bndPresentation (theDI, aPrs, aName, anAction);
}
}
- else if (TheAISContext()->NbCurrents() > 0)
+ else if (aCtx->NbCurrents() > 0)
{
// remove all currently selected objects
for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
}
}
}
-
- // update the screen and redraw the view
- const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
- a3DView()->SetImmediateUpdate (isAutoUpdate);
- if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
- || aToUpdate == ViewerTest_RM_RedrawForce)
- {
- TheAISContext()->UpdateCurrentViewer();
- }
-
return 0;
}
Standard_Integer theArgNb,
const char** theArgVec)
{
+ Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
if (theArgNb < 2)
{
std::cout << theArgVec[0] << "Error: wrong syntax!\n";
return 1;
}
- else if (a3DView().IsNull())
+ else if (aCtx.IsNull())
{
ViewerTest::ViewerInit();
std::cout << "Command vinit should be called before!\n";
// return 1;
+ aCtx = ViewerTest::GetAISContext();
}
- const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
+ ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
if (aCtx->HasOpenedContext())
{
aCtx->CloseLocalContext();
}
- ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
- Standard_Integer isMutable = -1;
+ Standard_Integer isMutable = -1;
for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
{
const TCollection_AsciiString aName = theArgVec[anArgIter];
TCollection_AsciiString aNameCase = aName;
aNameCase.LowerCase();
- if (parseRedrawMode (aName, aToUpdate))
+ if (anUpdateTool.parseRedrawMode (aName))
{
continue;
}
TheNISContext()->Display (aShape);
}
}
-
- const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
- a3DView()->SetImmediateUpdate (isAutoUpdate);
- if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
- || aToUpdate == ViewerTest_RM_RedrawForce)
- {
- // update the screen and redraw the view
- aCtx->UpdateCurrentViewer();
- }
return 0;
}
--- /dev/null
+// Created on: 2014-04-24
+// Created by: Kirill Gavrilov
+// Copyright (c) 2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#include <ViewerTest_AutoUpdater.hxx>
+
+//=======================================================================
+//function : ViewerTest_AutoUpdater
+//purpose :
+//=======================================================================
+ViewerTest_AutoUpdater::ViewerTest_AutoUpdater (const Handle(AIS_InteractiveContext)& theContext,
+ const Handle(V3d_View)& theView)
+: myContext (theContext),
+ myView (theView),
+ myToUpdate (RedrawMode_Auto),
+ myWasAutoUpdate (Standard_False)
+{
+ if (!theView.IsNull())
+ {
+ myWasAutoUpdate = theView->SetImmediateUpdate (Standard_False);
+ }
+}
+
+//=======================================================================
+//function : ~ViewerTest_AutoUpdater
+//purpose :
+//=======================================================================
+ViewerTest_AutoUpdater::~ViewerTest_AutoUpdater()
+{
+ Update();
+}
+
+//=======================================================================
+//function : parseRedrawMode
+//purpose :
+//=======================================================================
+Standard_Boolean ViewerTest_AutoUpdater::parseRedrawMode (const TCollection_AsciiString& theArg)
+{
+ TCollection_AsciiString anArgCase (theArg);
+ anArgCase.LowerCase();
+ if (anArgCase == "-update"
+ || anArgCase == "-redraw")
+ {
+ myToUpdate = RedrawMode_Forced;
+ return Standard_True;
+ }
+ else if (anArgCase == "-noupdate"
+ || anArgCase == "-noredraw")
+ {
+ myToUpdate = RedrawMode_Suppressed;
+ return Standard_True;
+ }
+ return Standard_False;
+}
+
+//=======================================================================
+//function : Invalidate
+//purpose :
+//=======================================================================
+void ViewerTest_AutoUpdater::Invalidate()
+{
+ myContext.Nullify();
+ if (myWasAutoUpdate)
+ {
+ myView->SetImmediateUpdate (myWasAutoUpdate);
+ }
+}
+
+//=======================================================================
+//function : Update
+//purpose :
+//=======================================================================
+void ViewerTest_AutoUpdater::Update()
+{
+ if (myContext.IsNull())
+ {
+ return;
+ }
+
+ // update the screen and redraw the view
+ myView->SetImmediateUpdate (myWasAutoUpdate);
+ if ((myWasAutoUpdate && myToUpdate != ViewerTest_AutoUpdater::RedrawMode_Suppressed)
+ || myToUpdate == ViewerTest_AutoUpdater::RedrawMode_Forced)
+ {
+ myContext->UpdateCurrentViewer();
+ }
+}
#include <AIS_DisplayMode.hxx>
#include <TColStd_MapOfInteger.hxx>
#include <AIS_MapOfInteractive.hxx>
+#include <ViewerTest_AutoUpdater.hxx>
#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
#include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
#include <ViewerTest_EventManager.hxx>
//=======================================================================
static Standard_Integer VSetLocation (Draw_Interpretor& /*di*/,
- Standard_Integer argc,
- const char ** argv)
+ Standard_Integer theArgNb,
+ const char** theArgVec)
{
Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
+ ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
if (aContext.IsNull())
{
- std::cout << argv[0] << "ERROR : use 'vinit' command before " << "\n";
+ std::cout << "Error: no active view!\n";
return 1;
}
- if (argc != 5)
+ TCollection_AsciiString aName;
+ gp_Vec aLocVec;
+ Standard_Boolean isSetLoc = Standard_False;
+
+ Standard_Integer anArgIter = 1;
+ for (; anArgIter < theArgNb; ++anArgIter)
{
- std::cout << "ERROR : Usage : " << argv[0] << " name x y z; new location" << "\n";
- return 1;
+ Standard_CString anArg = theArgVec[anArgIter];
+ if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
+ {
+ continue;
+ }
+ else if (aName.IsEmpty())
+ {
+ aName = anArg;
+ }
+ else if (!isSetLoc)
+ {
+ isSetLoc = Standard_True;
+ if (anArgIter + 1 >= theArgNb)
+ {
+ std::cout << "Error: syntax error at '" << anArg << "'\n";
+ return 1;
+ }
+ aLocVec.SetX (Draw::Atof (theArgVec[anArgIter++]));
+ aLocVec.SetY (Draw::Atof (theArgVec[anArgIter]));
+ if (anArgIter + 1 < theArgNb)
+ {
+ aLocVec.SetZ (Draw::Atof (theArgVec[++anArgIter]));
+ }
+ }
+ else
+ {
+ std::cout << "Error: unknown argument '" << anArg << "'\n";
+ return 1;
+ }
}
- TCollection_AsciiString aName (argv[1]);
- Standard_Real aX = Draw::Atof (argv[2]);
- Standard_Real aY = Draw::Atof (argv[3]);
- Standard_Real aZ = Draw::Atof (argv[4]);
-
// find object
- ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
+ const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
Handle(AIS_InteractiveObject) anIObj;
- if (!aMap.IsBound2 (aName))
+ if (aMap.IsBound2 (aName))
{
- std::cout << "Use 'vdisplay' before" << "\n";
- return 1;
+ anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
}
- else
+ if (anIObj.IsNull())
{
- anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
-
- // not an AIS_InteractiveObject
- if (anIObj.IsNull())
- {
- std::cout << argv[1] << " : Not an AIS interactive object" << "\n";
- return 1;
- }
-
- gp_Trsf aTrsf;
- aTrsf.SetTranslation (gp_Vec (aX, aY, aZ));
- TopLoc_Location aLocation (aTrsf);
- aContext->SetLocation (anIObj, aLocation);
- aContext->UpdateCurrentViewer();
+ std::cout << "Error: object '" << aName << "' is not displayed!\n";
+ return 1;
}
+ gp_Trsf aTrsf;
+ aTrsf.SetTranslation (aLocVec);
+ TopLoc_Location aLocation (aTrsf);
+ aContext->SetLocation (anIObj, aLocation);
return 0;
}
__FILE__,VDrawSphere,group);
theCommands.Add ("vsetlocation",
- "vsetlocation : name x y z; set new location for an interactive object",
+ "vsetlocation [-noupdate|-update] name x y z"
+ "\n\t\t: Set new location for an interactive object.",
__FILE__, VSetLocation, group);
theCommands.Add (