Salome HOME
API modif of vtkOpenGLTexture::ResampleToPowerOfTwo
[modules/gui.git] / src / SVTK / SVTK_UpdateRateDlg.cxx
index 7f31fb2b93354d63514ae8d25006e2866bb5bbf2..67b8e3a7f4c5b04bfe9ffce85408dd5b9656d702 100644 (file)
@@ -1,48 +1,46 @@
-//  SALOME VTKViewer : build VTK viewer into Salome desktop
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  This library is free software; you can redistribute it and/or 
-//  modify it under the terms of the GNU Lesser General Public 
-//  License as published by the Free Software Foundation; either 
-//  version 2.1 of the License. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  Lesser General Public License for more details. 
-// 
-//  You should have received a copy of the GNU Lesser General Public 
-//  License along with this library; if not, write to the Free Software 
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
-// 
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
+//  SALOME VTKViewer : build VTK viewer into Salome desktop
 //  File   : 
 //  Author : 
-//  Module : SALOME
-//  $Header$
 
 #include "SVTK_UpdateRateDlg.h"
 
-#include "SVTK_MainWindow.h"
+#include "SVTK_ViewWindow.h"
 #include "SVTK_RenderWindowInteractor.h"
 #include "VTKViewer_Algorithm.h"
 #include "SALOME_Actor.h"
 
-#include "QtxDblSpinBox.h"
+#include "QtxDoubleSpinBox.h"
 #include "QtxAction.h"
 
 #include <sstream>
 
-#include <qgroupbox.h>
-#include <qlabel.h>
-#include <qpushbutton.h>
-#include <qlayout.h>
-#include <qlineedit.h>
+#include <QGroupBox>
+#include <QLabel>
+#include <QPushButton>
+#include <QGridLayout>
+#include <QLineEdit>
 
 #include <vtkGenericRenderWindowInteractor.h>
 #include <vtkCallbackCommand.h>
 #include <vtkMapper.h>
 #include <vtkDataSet.h>
 
-static vtkFloatingPointType OFF_UPDATE_RATE = 0.00001;
-static vtkFloatingPointType FLOAT_TOLERANCE = 1.0 / VTK_LARGE_FLOAT;
-
-using namespace std;
+static double OFF_UPDATE_RATE = 0.0001;
+static double FLOAT_TOLERANCE = 1.0 / VTK_FLOAT_MAX;
 
 namespace
 {
@@ -64,12 +60,12 @@ namespace
   GetUpdateRate(SVTK_RenderWindowInteractor* theRWInteractor)
   {
     if(vtkRenderer *aRenderer = theRWInteractor->getRenderer()){
-      vtkFloatingPointType aLastRenderTimeInSeconds = aRenderer->GetLastRenderTimeInSeconds();
+      double aLastRenderTimeInSeconds = aRenderer->GetLastRenderTimeInSeconds();
       if(aLastRenderTimeInSeconds > FLOAT_TOLERANCE){
-       std::ostringstream aStr;
-       vtkFloatingPointType aFPS = 1.0 / aLastRenderTimeInSeconds;
-       aStr<<aFPS;
-       return QString(aStr.str().c_str());
+        std::ostringstream aStr;
+        double aFPS = 1.0 / aLastRenderTimeInSeconds;
+        aStr<<aFPS;
+        return QString(aStr.str().c_str());
       }
     }
     return "Inf";
@@ -79,8 +75,8 @@ namespace
   //----------------------------------------------------------------------------
   struct TRenderTimeMultiplier
   {
-    vtkFloatingPointType myVTKMultiplier;
-    vtkFloatingPointType mySALOMEMultiplier;
+    double myVTKMultiplier;
+    double mySALOMEMultiplier;
 
     TRenderTimeMultiplier():
       myVTKMultiplier(0.0),
@@ -91,9 +87,9 @@ namespace
     operator()(vtkActor* theActor)
     {
       if(theActor->GetVisibility()){
-       myVTKMultiplier += theActor->GetAllocatedRenderTime();
-       if(dynamic_cast<SALOME_Actor*>(theActor))
-         mySALOMEMultiplier += theActor->GetAllocatedRenderTime();
+        myVTKMultiplier += theActor->GetAllocatedRenderTime();
+        if(dynamic_cast<SALOME_Actor*>(theActor))
+          mySALOMEMultiplier += theActor->GetAllocatedRenderTime();
       }
     }
   };
@@ -101,18 +97,19 @@ namespace
 
   //----------------------------------------------------------------------------
   inline
-  vtkFloatingPointTyp
+  doubl
   AdjustUpdateRate(SVTK_RenderWindowInteractor* theRWInteractor,
-                  vtkFloatingPointType theUpdateRate)
+                   double theUpdateRate)
   {
     if(vtkRenderer *aRenderer = theRWInteractor->getRenderer()){
-      if(vtkActorCollection *anActorCollection = aRenderer->GetActors()){
-       TRenderTimeMultiplier aMultiplier;
-       using namespace VTK;
-       aMultiplier = ForEach<vtkActor>(anActorCollection,
-                                       aMultiplier);
-       if(aMultiplier.mySALOMEMultiplier > FLOAT_TOLERANCE)
-         theUpdateRate *= aMultiplier.mySALOMEMultiplier / aMultiplier.myVTKMultiplier;
+      VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
+      if(vtkActorCollection *anActorCollection = aCopy.GetActors()){
+        TRenderTimeMultiplier aMultiplier;
+        using namespace VTK;
+        aMultiplier = ForEach<vtkActor>(anActorCollection,
+                                        aMultiplier);
+        if(aMultiplier.mySALOMEMultiplier > FLOAT_TOLERANCE)
+          theUpdateRate *= aMultiplier.mySALOMEMultiplier / aMultiplier.myVTKMultiplier;
       }
     }
     return theUpdateRate;
@@ -131,11 +128,11 @@ namespace
     operator()(SALOME_Actor* theActor)
     {
       if(theActor->GetVisibility()){
-       if(vtkMapper *aMapper = theActor->GetMapper()){
-         if(vtkDataSet *aDataSet = aMapper->GetInput()){
-           myCounter += aDataSet->GetNumberOfCells();
-         }
-       }
+        if(vtkMapper *aMapper = theActor->GetMapper()){
+          if(vtkDataSet *aDataSet = aMapper->GetInput()){
+            myCounter += aDataSet->GetNumberOfCells();
+          }
+        }
       }
     }
   };
@@ -147,12 +144,13 @@ namespace
   GetNumberOfCells(SVTK_RenderWindowInteractor* theRWInteractor)
   {
     if(vtkRenderer *aRenderer = theRWInteractor->getRenderer()){
-      if(vtkActorCollection *anActorCollection = aRenderer->GetActors()){
-       TCellsCounter aCounter;
-       using namespace VTK;
-       aCounter = ForEach<SALOME_Actor>(anActorCollection,
-                                        aCounter);
-       return QString::number(aCounter.myCounter);
+      VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
+      if(vtkActorCollection *anActorCollection = aCopy.GetActors()){
+        TCellsCounter aCounter;
+        using namespace VTK;
+        aCounter = ForEach<SALOME_Actor>(anActorCollection,
+                                         aCounter);
+        return QString::number(aCounter.myCounter);
       }
     }
     
@@ -165,11 +163,11 @@ namespace
 */
 SVTK_UpdateRateDlg
 ::SVTK_UpdateRateDlg(QtxAction* theAction,
-                    SVTK_MainWindow* theParent,
-                    const char* theName):
-  SVTK_DialogBase(theAction,
-                 theParent, 
-                 theName),
+                     SVTK_ViewWindow* theParent,
+                     const char* theName):
+  ViewerTools_DialogBase(theAction,
+                         theParent, 
+                         theName),
   myPriority(0.0),
   myEventCallbackCommand(vtkCallbackCommand::New()),
   myRWInteractor(theParent->GetInteractor()),
@@ -178,25 +176,26 @@ SVTK_UpdateRateDlg
   vtkRenderWindowInteractor* aRWI = myRWInteractor->GetDevice();
   bool anIsEnabledUpdateRate = false;
 
-  setCaption(tr("DLG_TITLE"));
-  QVBoxLayout* aVBoxLayout = new QVBoxLayout(this, 5, 5);
+  setWindowTitle(tr("DLG_TITLE"));
+  QVBoxLayout* aVBoxLayout = new QVBoxLayout(this);
+  aVBoxLayout->setMargin(5);
+  aVBoxLayout->setSpacing(5);
   {
     QGroupBox* aGroupBox = new QGroupBox(tr("INPUT_FRAME_TITLE"), this);
-    aGroupBox->setColumnLayout(0, Qt::Vertical );
-    aGroupBox->layout()->setSpacing( 6 );
-    aGroupBox->layout()->setMargin( 11 );
 
     aGroupBox->setCheckable(true);
     aGroupBox->setChecked(anIsEnabledUpdateRate);
     myIsEnableUpdateRateGroupBox = aGroupBox;
 
-    QGridLayout* aGridLayout = new QGridLayout(aGroupBox->layout());
+    QGridLayout* aGridLayout = new QGridLayout(aGroupBox);
+    aGridLayout->setSpacing( 6 );
+    aGridLayout->setMargin( 11 );
     {
       QLabel* aLabel = new QLabel(tr("DESIRED"), aGroupBox);
       aLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
       aGridLayout->addWidget(aLabel, 0, 0);
 
-      QtxDblSpinBox* aDblSpinBox = new QtxDblSpinBox(OFF_UPDATE_RATE, VTK_LARGE_FLOAT, 2, aGroupBox);
+      QtxDoubleSpinBox* aDblSpinBox = new QtxDoubleSpinBox(OFF_UPDATE_RATE, VTK_FLOAT_MAX, 2, aGroupBox);
       aDblSpinBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
       aGridLayout->addWidget(aDblSpinBox, 0, 1);
 
@@ -210,7 +209,7 @@ SVTK_UpdateRateDlg
       aLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
       aGridLayout->addWidget(aLabel, 1, 0);
 
-      QtxDblSpinBox* aDblSpinBox = new QtxDblSpinBox(OFF_UPDATE_RATE, VTK_LARGE_FLOAT, 2, aGroupBox);
+      QtxDoubleSpinBox* aDblSpinBox = new QtxDoubleSpinBox(OFF_UPDATE_RATE, VTK_FLOAT_MAX, 2, aGroupBox);
       aDblSpinBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
       aGridLayout->addWidget(aDblSpinBox, 1, 1);
 
@@ -223,18 +222,17 @@ SVTK_UpdateRateDlg
   }
   {
     QGroupBox* aGroupBox = new QGroupBox(tr("INFORMATION_FRAME_TITLE"), this);
-    aGroupBox->setColumnLayout(0, Qt::Vertical );
-    aGroupBox->layout()->setSpacing( 6 );
-    aGroupBox->layout()->setMargin( 11 );
-
-    QGridLayout* aGridLayout = new QGridLayout(aGroupBox->layout());
+    
+    QGridLayout* aGridLayout = new QGridLayout(aGroupBox);
+    aGridLayout->layout()->setSpacing( 6 );
+    aGridLayout->layout()->setMargin( 11 );
     {
       QLabel* aLabel = new QLabel(tr("CURRENT_FPS"), aGroupBox);
       aLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
       aGridLayout->addWidget(aLabel, 0, 0);
 
       QLineEdit* aLineEdit = new QLineEdit( aGroupBox );
-      aLineEdit->setReadOnly( TRUE );
+      aLineEdit->setReadOnly( true );
       aGridLayout->addWidget(aLineEdit, 0, 1);
 
       myCurrentUpdateRateLineEdit = aLineEdit;
@@ -246,7 +244,7 @@ SVTK_UpdateRateDlg
       aGridLayout->addWidget(aLabel, 1, 0);
 
       QLineEdit* aLineEdit = new QLineEdit( aGroupBox );
-      aLineEdit->setReadOnly( TRUE );
+      aLineEdit->setReadOnly( true );
       aGridLayout->addWidget(aLineEdit, 1, 1);
 
       myNumberOfCellsLineEdit = aLineEdit;
@@ -261,23 +259,23 @@ SVTK_UpdateRateDlg
     aHBoxLayout->setSpacing(6);
     {
       QPushButton* aPushButton = new QPushButton(tr("OK"), aGroupBox);
-      aPushButton->setDefault(TRUE);
-      aPushButton->setAutoDefault(TRUE);
+      aPushButton->setDefault(true);
+      aPushButton->setAutoDefault(true);
       aHBoxLayout->addWidget(aPushButton);
       connect(aPushButton, SIGNAL(clicked()), this, SLOT(onClickOk()));
     }
     {
       QPushButton* aPushButton = new QPushButton(tr("Apply"), aGroupBox);
-      aPushButton->setDefault(TRUE);
-      aPushButton->setAutoDefault(TRUE);
+      aPushButton->setDefault(true);
+      aPushButton->setAutoDefault(true);
       aHBoxLayout->addWidget(aPushButton);
       connect(aPushButton, SIGNAL(clicked()), this, SLOT(onClickApply()));
     }
     aHBoxLayout->addStretch();
     {
       QPushButton* aPushButton = new QPushButton(tr("Close"), aGroupBox);
-      aPushButton->setDefault(TRUE);
-      aPushButton->setAutoDefault(TRUE);
+      aPushButton->setDefault(true);
+      aPushButton->setAutoDefault(true);
       aHBoxLayout->addWidget(aPushButton);
       connect(aPushButton, SIGNAL(clicked()), this, SLOT(onClickClose()));
     }
@@ -294,8 +292,8 @@ SVTK_UpdateRateDlg
   myEventCallbackCommand->SetCallback(SVTK_UpdateRateDlg::ProcessEvents);
   vtkRenderer *aRenderer = myRWInteractor->getRenderer();
   aRenderer->AddObserver(vtkCommand::EndEvent,
-                        myEventCallbackCommand.GetPointer(), 
-                        myPriority);
+                         myEventCallbackCommand.GetPointer(), 
+                         myPriority);
 }
 
 /*!
@@ -313,9 +311,9 @@ SVTK_UpdateRateDlg
 void 
 SVTK_UpdateRateDlg
 ::ProcessEvents(vtkObject* vtkNotUsed(theObject), 
-               unsigned long theEvent,
-               void* theClientData, 
-               void* vtkNotUsed(theCallData))
+                unsigned long theEvent,
+                void* theClientData, 
+                void* vtkNotUsed(theCallData))
 {
   SVTK_UpdateRateDlg* self = reinterpret_cast<SVTK_UpdateRateDlg*>(theClientData);
 
@@ -334,18 +332,13 @@ SVTK_UpdateRateDlg
 {
   vtkRenderWindowInteractor* aRWI = myRWInteractor->GetDevice();
 
-  vtkFloatingPointType anUpdateRate;
-  if(myIsEnableUpdateRateGroupBox->isChecked()){
-    anUpdateRate = AdjustUpdateRate(myRWInteractor,myDesiredUpdateRateSblSpinBox->value());
-    aRWI->SetDesiredUpdateRate(anUpdateRate);
-    anUpdateRate = AdjustUpdateRate(myRWInteractor,myStillUpdateRateSblSpinBox->value());
-    aRWI->SetStillUpdateRate(anUpdateRate);
-  }else{
-    aRWI->SetDesiredUpdateRate(OFF_UPDATE_RATE);
-    aRWI->SetStillUpdateRate(OFF_UPDATE_RATE);
-  }
+  double aDesirableUpdateRate = aRWI->GetDesiredUpdateRate();
+  double aStillUpdateRate = aRWI->GetStillUpdateRate();
+  bool isUpdateRate = (aDesirableUpdateRate != OFF_UPDATE_RATE) || (aStillUpdateRate != OFF_UPDATE_RATE);
 
-  myRWInteractor->getRenderWindow()->Render();
+  myIsEnableUpdateRateGroupBox->setChecked(isUpdateRate);
+  myDesiredUpdateRateSblSpinBox->setValue(aDesirableUpdateRate);
+  myStillUpdateRateSblSpinBox->setValue(aStillUpdateRate);
 }
 
 /*!
@@ -355,7 +348,7 @@ void
 SVTK_UpdateRateDlg
 ::onClickOk()
 {
-  Update();
+  onClickApply();
   onClickClose();
 }
 
@@ -366,7 +359,20 @@ void
 SVTK_UpdateRateDlg
 ::onClickApply()
 {
-  Update();
+  vtkRenderWindowInteractor* aRWI = myRWInteractor->GetDevice();
+  double anUpdateRate;
+  if (myIsEnableUpdateRateGroupBox->isChecked()) {
+    anUpdateRate = AdjustUpdateRate(myRWInteractor,myDesiredUpdateRateSblSpinBox->value());
+    aRWI->SetDesiredUpdateRate(anUpdateRate);
+    anUpdateRate = AdjustUpdateRate(myRWInteractor,myStillUpdateRateSblSpinBox->value());
+    aRWI->SetStillUpdateRate(anUpdateRate);
+  }
+  else {
+    aRWI->SetDesiredUpdateRate(OFF_UPDATE_RATE);
+    aRWI->SetStillUpdateRate(OFF_UPDATE_RATE);
+  }
+
+  myRWInteractor->getRenderWindow()->Render();
 }
 
 /*!